結果
問題 | No.103 素因数ゲーム リターンズ |
ユーザー | koyumeishi |
提出日時 | 2014-12-14 23:37:50 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 2 ms / 5,000 ms |
コード長 | 1,369 bytes |
コンパイル時間 | 711 ms |
コンパイル使用メモリ | 85,536 KB |
実行使用メモリ | 4,384 KB |
最終ジャッジ日時 | 2023-09-02 14:32:31 |
合計ジャッジ時間 | 1,769 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,380 KB |
testcase_01 | AC | 1 ms
4,376 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 2 ms
4,376 KB |
testcase_05 | AC | 2 ms
4,376 KB |
testcase_06 | AC | 1 ms
4,376 KB |
testcase_07 | AC | 1 ms
4,380 KB |
testcase_08 | AC | 2 ms
4,384 KB |
testcase_09 | AC | 1 ms
4,376 KB |
testcase_10 | AC | 2 ms
4,380 KB |
testcase_11 | AC | 1 ms
4,376 KB |
testcase_12 | AC | 1 ms
4,376 KB |
testcase_13 | AC | 2 ms
4,376 KB |
testcase_14 | AC | 2 ms
4,380 KB |
testcase_15 | AC | 2 ms
4,376 KB |
testcase_16 | AC | 2 ms
4,380 KB |
testcase_17 | AC | 2 ms
4,380 KB |
testcase_18 | AC | 2 ms
4,376 KB |
testcase_19 | AC | 2 ms
4,380 KB |
testcase_20 | AC | 1 ms
4,380 KB |
testcase_21 | AC | 2 ms
4,380 KB |
testcase_22 | AC | 2 ms
4,380 KB |
testcase_23 | AC | 2 ms
4,380 KB |
testcase_24 | AC | 1 ms
4,376 KB |
ソースコード
#include <iostream> #include <vector> #include <cstdio> #include <sstream> #include <map> #include <string> #include <algorithm> #include <queue> #include <cmath> #include <set> using namespace std; vector<pair<long long, long long> > prime_factorization(long long N){ vector< pair<long long, long long> > ret; for(long long i=2; i*i<=N; i++){ long long tmp = 0; while(N%i==0){ tmp++; N/=i; } if(tmp>0){ ret.push_back( make_pair(i, tmp) ); } } if(N!=1){ ret.push_back( make_pair(N, 1) ); } return ret; } int grundy(vector<int> &memo, int x){ if(memo[x] >= 0) return memo[x]; set<int> s; auto p = prime_factorization(x); for(int i=0; i<p.size(); i++){ s.insert( grundy(memo, x/p[i].first) ); if(p[i].second >= 2) s.insert( grundy(memo, x/(p[i].first*p[i].first)) ); } int res = 0; while( s.count(res) ) res++; memo[x] = res; return res; } int main(){ int n; cin >> n; vector<int> m(n); for(int i=0; i<n; i++) cin >> m[i]; int ans = 0; vector<int> memo( *max_element(m.begin(), m.end()) + 1, -1); memo[1] = 0; for(int i=0; i<n; i++){ ans ^= grundy(memo, m[i]); } /* for(int i=1; i<=*max_element(m.begin(), m.end()); i++){ cerr << i << " " << memo[i] << endl; } cerr << endl; */ cout << (ans==0?"Bob":"Alice") << endl; return 0; }