結果

問題 No.153 石の山
ユーザー lucky3977lucky3977
提出日時 2018-10-09 18:33:33
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 781 bytes
コンパイル時間 745 ms
コンパイル使用メモリ 73,008 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 19:10:41
合計ジャッジ時間 1,807 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 2 ms
5,376 KB
testcase_25 AC 2 ms
5,376 KB
testcase_26 AC 2 ms
5,376 KB
testcase_27 AC 2 ms
5,376 KB
testcase_28 AC 2 ms
5,376 KB
testcase_29 AC 2 ms
5,376 KB
testcase_30 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'void init_grundy()':
main.cpp:11:45: warning: iteration 108 invokes undefined behavior [-Waggressive-loop-optimizations]
   11 |         for(int i = 2; i <= 110; i++) gr[i] = -1;
      |                                       ~~~~~~^~~~
main.cpp:11:26: note: within this loop
   11 |         for(int i = 2; i <= 110; i++) gr[i] = -1;
      |                        ~~^~~~~~
main.cpp:11:45: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 436 bytes into a region of size 432 overflows the destination [-Wstringop-overflow=]
   11 |         for(int i = 2; i <= 110; i++) gr[i] = -1;
      |                                       ~~~~~~^~~~
main.cpp:7:5: note: at offset 8 into destination object 'gr' of size 440
    7 | int gr[110];
      |     ^~
In function 'void init_grundy()',
    inlined from 'int main()' at main.cpp:32:13:
main.cpp:11:45: warning: 'void* __builtin_memset(void*, int, long unsigned int)' writing 436 bytes into a region of size 432 overflows the destination [-Wstringop-overflow=]
   11 |         for(int i = 2; i <= 110; i++) gr[i] = -1;
      |                                       ~~~~~~^~~~
main.cpp: In function 'int main()':
main.cpp:7:5: note: at offset 8 into destination object 'gr' of size 440
    7 | int gr[110];
      |     ^~

ソースコード

diff #

#include<iostream>
#include<set>


using namespace std;

int gr[110];

void init_grundy(){
	gr[1] = 0;
	for(int i = 2; i <= 110; i++) gr[i] = -1;
}

int grundy(int x){
	if(gr[x] >= 0) return gr[x];
	set<int> s;
	if(x % 2 == 0) s.insert(grundy(x / 2) ^ grundy(x / 2));
	else s.insert(grundy(x / 2) ^ grundy(x / 2 + 1));
	if(x >= 3){
		if(x % 3 == 0) s.insert(grundy(x / 3) ^ grundy(x / 3) ^ grundy(x / 3));
		else if(x % 3 == 1) s.insert(grundy(x / 3) ^ grundy(x / 3) ^ grundy(x / 3 + 1));
		else s.insert(grundy(x / 3) ^ grundy(x / 3 + 1) ^ grundy(x / 3 + 1));
	}
	int res = 0;
	while(s.find(res) != s.end()) res++;
	return gr[x] = res;
}

int main(){
	int n, ans = 0;
	cin >> n;
	init_grundy();
	if(grundy(n)){
		cout << "A" << endl;
	}else{
		cout << "B" << endl;
	}
	return 0;
}
0