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

11316번 - Train of Threes 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 256 MB317735.000%

문제

Threes! is a puzzle game available on iOS, Android, and elsewhere. Its premise is simple, yet provides a deep structure: Repeatedly match adjacent numbers to form larger numbers. Here we will play a simplified version of the game.

The game starts with an array of N numbers. Each number is either 1 or 2 or some number on the form 3 × 2i for some integer i ≥ 0.

We can combine two matching adjacent numbers to form larger numbers. We can combine a 1 adjacent to a 2 into a single 3. We can combine two adjacent 3s into a single 6, we can combine two adjacent 6s into a single 12, and we can in general combine two identical adjacent numbers higher than 3 into a single number that will be their sum. The 1s and 2s are special in that a 1 can only be matched with a 2, and a 2 can only be matched with a 1.

The goal of the game is to form the largest integer possible. The game ends when we can no longer combine two adjacent numbers. Consider we e.g. start with the array {12, 24, 6, 1, 2, 3, 12, 3, 3, 6, 1, 2, 2, 1, 24} then the largest number we can form is 48.

입력

The first line of the input contains an integer T, the number of test cases (1 ≤ T ≤ 1, 000). Then follows 2T lines. The first line of each test case contains an integer N, the size of the array (1 ≤ N ≤ 10, 000). Then next line contains N integers, where each integer is 1, 2, or a number on the form 3 × 2i for some integer 0 ≤ i ≤ 11.

출력

For each of the T test cases, output the largest integer that can be formed.

제한

예제 입력 1

3
5
1 2 2 2 2
6
24 12 6 3 2 1
4
3 3 3 3

예제 출력 1

3
48
12

힌트

출처

Contest > Calgary Collegiate Programming Contest > CCPC 2015 Division 1 E번

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

출처

대학교 대회

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

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