結果

問題 No.1816 MUL-DIV Game
ユーザー merlinmerlin
提出日時 2022-01-21 22:11:42
言語 Java21
(openjdk 21)
結果
AC  
実行時間 669 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 2,147 ms
コンパイル使用メモリ 76,468 KB
実行使用メモリ 78,564 KB
最終ジャッジ日時 2023-08-17 06:17:32
合計ジャッジ時間 12,325 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
49,344 KB
testcase_01 AC 43 ms
49,456 KB
testcase_02 AC 43 ms
49,576 KB
testcase_03 AC 43 ms
49,496 KB
testcase_04 AC 41 ms
49,520 KB
testcase_05 AC 42 ms
49,196 KB
testcase_06 AC 43 ms
49,520 KB
testcase_07 AC 43 ms
49,320 KB
testcase_08 AC 42 ms
49,508 KB
testcase_09 AC 169 ms
55,916 KB
testcase_10 AC 379 ms
60,784 KB
testcase_11 AC 349 ms
60,924 KB
testcase_12 AC 332 ms
58,568 KB
testcase_13 AC 416 ms
64,732 KB
testcase_14 AC 326 ms
60,800 KB
testcase_15 AC 383 ms
60,824 KB
testcase_16 AC 184 ms
56,260 KB
testcase_17 AC 518 ms
71,848 KB
testcase_18 AC 503 ms
76,112 KB
testcase_19 AC 353 ms
60,896 KB
testcase_20 AC 557 ms
75,736 KB
testcase_21 AC 327 ms
59,144 KB
testcase_22 AC 282 ms
58,336 KB
testcase_23 AC 43 ms
49,444 KB
testcase_24 AC 43 ms
49,420 KB
testcase_25 AC 612 ms
78,192 KB
testcase_26 AC 622 ms
78,052 KB
testcase_27 AC 669 ms
78,036 KB
testcase_28 AC 634 ms
78,184 KB
testcase_29 AC 648 ms
78,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader bu=new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb=new StringBuilder();
        int n=Integer.parseInt(bu.readLine());
        int i; long a;

        String s[]=bu.readLine().split(" ");
        TreeMap<Long,Integer> tm=new TreeMap<>();
        for(i=0;i<n;i++)
        {
            a=Integer.parseInt(s[i]);
            tm.put(a,tm.getOrDefault(a,0)+1);
        }

        long ans=-1;
        boolean alice=true;
        while(true)
        {
            long lo=tm.higherKey(-1l);
            if(tm.size()==1 && tm.get(lo)==1)
            {
                ans=lo;
                break;
            }

            if(alice)
            {
                remove(tm,lo);
                long lo2=tm.higherKey(lo-1);
                remove(tm,lo2);
                tm.put(lo*lo2,tm.getOrDefault(lo*lo2,0)+1);
            }
            else
            {
                long hi=tm.lowerKey(Long.MAX_VALUE);
                remove(tm,hi);
                long hi2=tm.lowerKey(hi+1);
                remove(tm,hi2);
                tm.put(1l,tm.getOrDefault(1l,0)+1);
            }

            alice=!alice;
        }
        System.out.println(ans);
    }

    static void remove(TreeMap<Long,Integer> tm,long x)
    {
        int v=tm.get(x);
        if(v==1) tm.remove(x);
        else tm.put(x,v-1);
    }
}
0