結果

問題 No.153 石の山
ユーザー GrenacheGrenache
提出日時 2016-05-24 23:46:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 131 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 3,728 ms
コンパイル使用メモリ 75,880 KB
実行使用メモリ 57,900 KB
最終ジャッジ日時 2023-08-04 17:30:36
合計ジャッジ時間 9,111 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 128 ms
55,460 KB
testcase_01 AC 129 ms
55,860 KB
testcase_02 AC 127 ms
55,700 KB
testcase_03 AC 128 ms
56,068 KB
testcase_04 AC 129 ms
55,956 KB
testcase_05 AC 129 ms
55,988 KB
testcase_06 AC 127 ms
55,728 KB
testcase_07 AC 130 ms
55,776 KB
testcase_08 AC 129 ms
55,888 KB
testcase_09 AC 127 ms
55,848 KB
testcase_10 AC 130 ms
55,868 KB
testcase_11 AC 129 ms
55,700 KB
testcase_12 AC 131 ms
55,996 KB
testcase_13 AC 131 ms
55,424 KB
testcase_14 AC 130 ms
55,456 KB
testcase_15 AC 128 ms
55,480 KB
testcase_16 AC 128 ms
55,700 KB
testcase_17 AC 129 ms
56,280 KB
testcase_18 AC 129 ms
55,876 KB
testcase_19 AC 128 ms
55,656 KB
testcase_20 AC 127 ms
55,620 KB
testcase_21 AC 127 ms
55,452 KB
testcase_22 AC 129 ms
56,008 KB
testcase_23 AC 128 ms
55,748 KB
testcase_24 AC 128 ms
55,824 KB
testcase_25 AC 130 ms
55,788 KB
testcase_26 AC 131 ms
55,664 KB
testcase_27 AC 130 ms
56,008 KB
testcase_28 AC 131 ms
55,884 KB
testcase_29 AC 131 ms
55,716 KB
testcase_30 AC 131 ms
57,900 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main_yukicoder153_1 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int[] grundy = new int[n + 1];
        for (int i = 2; i <= n; i++) {
        	Set<Integer> st = new HashSet<>();

        	int g;
        	if (i % 2 == 0) {
        		g = grundy[i / 2] ^ grundy[i / 2];
        	} else {
        		g = grundy[i / 2] ^ grundy[i / 2 + 1];
        	}
        	st.add(g);

        	if (i % 3 == 0) {
        		g = grundy[i / 3] ^ grundy[i / 3] ^ grundy[i / 3];
        	} else if (i % 3 == 1) {
        		g = grundy[i / 3] ^ grundy[i / 3] ^ grundy[i / 3 + 1];
        	} else {
        		g = grundy[i / 3] ^ grundy[i / 3 + 1] ^ grundy[i / 3 + 1];
        	}
        	st.add(g);

        	for (int j = 0; true; j++) {
        		if (!st.contains(j)) {
        			grundy[i] = j;
        			break;
        		}
        	}
        }

        if (grundy[n] > 0) {
        	System.out.println("A");
        } else {
        	System.out.println("B");
        }

        sc.close();
    }
}
0