結果
問題 | No.1665 quotient replace |
ユーザー |
![]() |
提出日時 | 2021-09-04 20:37:04 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2,037 ms / 3,000 ms |
コード長 | 1,269 bytes |
コンパイル時間 | 798 ms |
コンパイル使用メモリ | 95,772 KB |
実行使用メモリ | 7,552 KB |
最終ジャッジ日時 | 2024-12-21 14:41:19 |
合計ジャッジ時間 | 31,370 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 41 |
ソースコード
/* -*- coding: utf-8 -*- * * 1665.cc: No.1665 quotient replace - yukicoder */ #include<cstdio> #include<cstdlib> #include<cstring> #include<cmath> #include<iostream> #include<bitset> #include<string> #include<vector> #include<map> #include<set> #include<stack> #include<list> #include<queue> #include<deque> #include<algorithm> #include<numeric> #include<utility> #include<complex> #include<functional> using namespace std; /* constant */ const int MAX_N = 1000000; const int MAX_A = 1000000; const int MAX_G = 240; /* typedef */ typedef bitset<MAX_G> bts; /* global variables */ int cache[MAX_A + 1]; /* subroutines */ int grundy(int a) { if (cache[a] >= 0) return cache[a]; bts bs; for (int p = 1; p * p <= a; p++) if (a % p == 0) { bs.set(grundy(p)); int q = a / p; if (q < a && q != p) bs.set(grundy(q)); } int g = 1; for (; bs.test(g); g++); return (cache[a] = g); } /* main */ int main() { memset(cache, -1, sizeof(cache)); cache[0] = cache[1] = 0; int n; scanf("%d", &n); int nim = 0; for (int i = 0; i < n; i++) { int ai; scanf("%d", &ai); //printf("grundy(%d) = %d\n", ai, grundy(ai)); nim ^= grundy(ai); } if (nim) puts("white"); else puts("black"); return 0; }