結果

問題 No.103 素因数ゲーム リターンズ
ユーザー 0x19f0x19f
提出日時 2017-12-10 04:17:36
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 863 bytes
コンパイル時間 1,452 ms
コンパイル使用メモリ 154,356 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-08-20 06:35:08
合計ジャッジ時間 2,757 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 2 ms
4,384 KB
testcase_11 AC 4 ms
4,376 KB
testcase_12 AC 8 ms
4,380 KB
testcase_13 AC 7 ms
4,376 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 10 ms
4,376 KB
testcase_16 AC 4 ms
4,376 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 5 ms
4,380 KB
testcase_19 AC 12 ms
4,376 KB
testcase_20 AC 6 ms
4,376 KB
testcase_21 AC 8 ms
4,380 KB
testcase_22 AC 7 ms
4,380 KB
testcase_23 AC 7 ms
4,380 KB
testcase_24 AC 3 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N, M[100];
ll memo[20000];
vector<ll> prime;

ll grundy(ll n) {
  ll &ret = memo[n];
  if(ret >= 0) return ret;
  if(n == 1) return ret = 0;

  set<ll> st;
  for(ll p : prime) {
    ll p1 = p, p2 = p * p;
    if(n % p1 == 0) st.insert(grundy(n / p1));
    if(n % p2 == 0) st.insert(grundy(n / p2));
  }
  ll g = 0;
  while(st.count(g)) g++;
  return ret = g;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> M[i];

  vector<bool> p(10000, true);
  p[0] = p[1] = false;
  REP(i, 0, 10000) if(p[i]) for(ll j = i + i; j < 10000; j += i) p[j] = false;
  REP(i, 0, 10000) if(p[i]) prime.push_back(i);

  REP(i, 0, 20000) memo[i] = -1;

  ll x = 0;
  REP(i, 0, N) x ^= grundy(M[i]);
  cout << (x != 0 ? "Alice" : "Bob") << endl;
}
0