結果

問題 No.153 石の山
ユーザー lucky3977lucky3977
提出日時 2018-10-09 18:33:33
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 781 bytes
コンパイル時間 794 ms
コンパイル使用メモリ 73,968 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-10-12 16:38:03
合計ジャッジ時間 1,899 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 27
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0