結果

問題 No.1816 MUL-DIV Game
ユーザー koanviolinkoanviolin
提出日時 2022-01-21 22:50:52
言語 Java21
(openjdk 21)
結果
AC  
実行時間 1,147 ms / 2,000 ms
コード長 2,058 bytes
コンパイル時間 2,137 ms
コンパイル使用メモリ 77,256 KB
実行使用メモリ 72,048 KB
最終ジャッジ日時 2023-08-17 07:12:40
合計ジャッジ時間 19,572 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
56,704 KB
testcase_01 AC 127 ms
56,220 KB
testcase_02 AC 127 ms
55,644 KB
testcase_03 AC 125 ms
56,152 KB
testcase_04 AC 124 ms
56,044 KB
testcase_05 AC 126 ms
55,936 KB
testcase_06 AC 124 ms
56,280 KB
testcase_07 AC 125 ms
55,892 KB
testcase_08 AC 125 ms
55,812 KB
testcase_09 AC 305 ms
60,428 KB
testcase_10 AC 600 ms
62,968 KB
testcase_11 AC 543 ms
62,288 KB
testcase_12 AC 466 ms
62,844 KB
testcase_13 AC 801 ms
69,640 KB
testcase_14 AC 603 ms
63,452 KB
testcase_15 AC 684 ms
63,140 KB
testcase_16 AC 364 ms
60,680 KB
testcase_17 AC 974 ms
70,308 KB
testcase_18 AC 957 ms
69,184 KB
testcase_19 AC 664 ms
62,464 KB
testcase_20 AC 998 ms
70,948 KB
testcase_21 AC 569 ms
62,912 KB
testcase_22 AC 506 ms
60,912 KB
testcase_23 AC 126 ms
55,612 KB
testcase_24 AC 128 ms
56,052 KB
testcase_25 AC 1,118 ms
72,048 KB
testcase_26 AC 910 ms
70,128 KB
testcase_27 AC 1,086 ms
71,480 KB
testcase_28 AC 904 ms
71,180 KB
testcase_29 AC 1,147 ms
71,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedInputStream;
import java.util.*;

public class Main {
    public static void main(String[] argv){
        Scanner sc = new Scanner(new BufferedInputStream(System.in));
        TreeMap<Long,Integer> s = new TreeMap();
        int n = sc.nextInt();
        long[] a= new long[n];
        for(int i = 0 ; i < n ; i++){
            a[i] = sc.nextLong();
            s.put(a[i], s.getOrDefault(a[i], 0) + 1);
        }

        if ( n>1 && n % 2 == 1) {
            System.out.println(1);
        } else {
            int t = 0;
            int tot = n;
           while(tot>1){
               if (t % 2 ==0) {
                   Map.Entry<Long, Integer> x = s.pollFirstEntry();
                   long key1 = x.getKey();
                   int val1 = x.getValue() - 1;
                   tot--;
                   if (val1 == 0 ) s.remove(key1);
                   else s.put(key1, val1);

                   Map.Entry<Long, Integer> y = s.pollFirstEntry();
                   long key2 = y.getKey();
                   int val2 = y.getValue() - 1;
                   tot--;
                   if(val2==0) s.remove(key2);
                   else s.put(key2, val2);
                   tot++;
                   s.put(key1*key2, s.getOrDefault(key1*key2, 0 )+ 1);

               }else{
                   Map.Entry<Long, Integer> x = s.pollLastEntry();
                   long key1 = x.getKey();
                   int val1 = x.getValue() - 1;
                   tot--;
                   if (val1 == 0) s.remove(key1);
                   else s.put(key1, val1);

                   Map.Entry<Long, Integer> y = s.pollLastEntry();
                   long key2 = y.getKey();
                   int val2 = y.getValue() - 1;
                   tot--;
                   if(val2 == 0) s.remove(key2);
                   else   s.put(key2, val2);
                   tot++;
                   s.put(1L, s.getOrDefault(1L, 0 )+ 1);
               }
               t^=1;
           }
           System.out.println(s.firstKey());
        }
    }
}
0