結果

問題 No.153 石の山
ユーザー kou6839kou6839
提出日時 2015-03-28 00:04:31
言語 Java21
(openjdk 21)
結果
AC  
実行時間 129 ms / 5,000 ms
コード長 661 bytes
コンパイル時間 2,674 ms
コンパイル使用メモリ 79,572 KB
実行使用メモリ 41,324 KB
最終ジャッジ日時 2024-04-22 15:28:22
合計ジャッジ時間 7,543 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 112 ms
40,320 KB
testcase_01 AC 127 ms
41,316 KB
testcase_02 AC 126 ms
41,264 KB
testcase_03 AC 126 ms
41,080 KB
testcase_04 AC 115 ms
39,928 KB
testcase_05 AC 124 ms
40,716 KB
testcase_06 AC 122 ms
40,936 KB
testcase_07 AC 112 ms
40,088 KB
testcase_08 AC 123 ms
41,148 KB
testcase_09 AC 114 ms
40,316 KB
testcase_10 AC 126 ms
41,284 KB
testcase_11 AC 128 ms
41,324 KB
testcase_12 AC 126 ms
40,908 KB
testcase_13 AC 116 ms
40,040 KB
testcase_14 AC 114 ms
40,244 KB
testcase_15 AC 117 ms
40,512 KB
testcase_16 AC 113 ms
40,364 KB
testcase_17 AC 123 ms
40,964 KB
testcase_18 AC 123 ms
41,084 KB
testcase_19 AC 116 ms
40,312 KB
testcase_20 AC 126 ms
41,252 KB
testcase_21 AC 125 ms
41,160 KB
testcase_22 AC 126 ms
41,288 KB
testcase_23 AC 116 ms
40,136 KB
testcase_24 AC 112 ms
40,380 KB
testcase_25 AC 110 ms
40,380 KB
testcase_26 AC 115 ms
40,312 KB
testcase_27 AC 129 ms
41,264 KB
testcase_28 AC 129 ms
41,280 KB
testcase_29 AC 114 ms
40,220 KB
testcase_30 AC 124 ms
41,140 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.math.BigInteger;
import java.util.*;
public class Main {
	static int rec(int x){
		if(grandy[x]!=-1) return grandy[x];
		
		Set<Integer> set = new HashSet<>();
		set.add(rec(x/2)^rec((x+1)/2));
		if(x>=3){
			set.add(rec(x/3)^rec((x+1)/3)^rec((x+2)/3));
		}
		int res=0;
		while(set.contains(res)) res++;
		return grandy[x]=res;
		}
	static int[] grandy;
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		grandy = new int[101];
		Arrays.fill(grandy, -1);
		grandy[1]=0;
		for(int i=1;i<101;i++) grandy[i]=rec(i);
		if(grandy[sc.nextInt()]==0){
			System.out.println("B");
		}else{
			System.out.println("A");
		}
	}
}
0