Logo
(追記) (追記ここまで)

14768번 - Nice Numbers 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 512 MB26121252.174%

문제

If you are familiar with the game 2048, this problem may make sense right away.

Either way, we will define our own one-dimensional version of the game:

You are given a list of numbers containing only powers of 2. You can “compress” this list by “pushing” it to the right. If two identical numbers are next to each other, push will cause them to merge. The “merge” in this context means that the two numbers are replaced by their sum. Each number can be merged only once—if they can merge with either of their neighbors, they merge with the one to the right. This process is evaluated from the right. For example, the list [2, 2, 2, 2] will become [4, 4] after one push. For another example, given a list [2, 2, 2], after a push, we end up with a new list [2, 4] and we cannot change it further by “pushing”.

Now, some of these lists, after some number of pushes, may end up with a single element. Using the example: [8, 2, 2, 4] ⇒ [8, 4, 4] ⇒ [8, 8] ⇒ [16].

If the list can be reduced to a single element list only by “pushing”, we call such a list nice.

Your task is to take a given list and make it nice by adding some (maybe zero) elements from {2, 4, 8}. To make this problem a bit easier, the initial list can contain only numbers in the set {2, 4, 8}.

입력

The first line of input contains a single positive integer T ≤ 100 indicating the number of test cases. Next T lines each contains a string of length 1 ≤ L ≤ 100, composed entirely of digits from the set {2, 4, 8} (our representation of the given list).

출력

For each test case, output a line containing the shortest nice list built out of the input list by inserting zero or more of digits from the set {2, 4, 8}. If there are multiple optimal solutions, output the lexicographically smallest one.

제한

예제 입력 1

3
222
8224
42424

예제 출력 1

2222
8224
422422448

힌트

출처

ICPC > Regionals > North America > Rocky Mountain Regional > 2016 Rocky Mountain Regional Contest H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /