結果

問題 No.153 石の山
ユーザー GrenacheGrenache
提出日時 2016-05-24 23:46:26
言語 Java21
(openjdk 21)
結果
AC  
実行時間 135 ms / 5,000 ms
コード長 1,097 bytes
コンパイル時間 6,833 ms
コンパイル使用メモリ 78,172 KB
実行使用メモリ 42,084 KB
最終ジャッジ日時 2024-04-22 15:35:26
合計ジャッジ時間 10,603 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
41,428 KB
testcase_01 AC 124 ms
41,200 KB
testcase_02 AC 123 ms
41,400 KB
testcase_03 AC 112 ms
41,432 KB
testcase_04 AC 123 ms
41,608 KB
testcase_05 AC 122 ms
41,552 KB
testcase_06 AC 108 ms
41,248 KB
testcase_07 AC 121 ms
41,152 KB
testcase_08 AC 119 ms
41,244 KB
testcase_09 AC 120 ms
42,084 KB
testcase_10 AC 135 ms
41,404 KB
testcase_11 AC 122 ms
41,516 KB
testcase_12 AC 122 ms
41,696 KB
testcase_13 AC 119 ms
41,420 KB
testcase_14 AC 119 ms
41,300 KB
testcase_15 AC 125 ms
41,456 KB
testcase_16 AC 113 ms
41,304 KB
testcase_17 AC 116 ms
41,408 KB
testcase_18 AC 122 ms
41,368 KB
testcase_19 AC 111 ms
41,216 KB
testcase_20 AC 111 ms
41,608 KB
testcase_21 AC 120 ms
41,312 KB
testcase_22 AC 111 ms
41,564 KB
testcase_23 AC 129 ms
41,400 KB
testcase_24 AC 123 ms
41,500 KB
testcase_25 AC 126 ms
41,392 KB
testcase_26 AC 120 ms
41,340 KB
testcase_27 AC 124 ms
41,428 KB
testcase_28 AC 109 ms
41,360 KB
testcase_29 AC 127 ms
41,516 KB
testcase_30 AC 125 ms
41,548 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