結果

問題 No.103 素因数ゲーム リターンズ
ユーザー たこしたこし
提出日時 2015-06-09 22:57:53
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 1,908 bytes
コンパイル時間 796 ms
コンパイル使用メモリ 98,676 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-20 20:26:06
合計ジャッジ時間 3,103 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <queue>
#include <complex>

#define INF_MIN 100000000
#define INF 1145141919
#define INF_MAX 2147483647
#define LL_MAX 9223372036854775807
#define EPS 1e-10
#define PI acos(-1)
#define LL long long

using namespace std;

#define MAX_N 101
#define MAX_M 10001

int N;
int M[MAX_N];

bool prime[MAX_M];
vector<int> primeList;
int grundy[MAX_M];

void init(){

  //素数を数え上げる
  for(int i = 2; i < MAX_M; i++){
    if(!prime[i]){
      primeList.push_back(i);
      for(int j = 2; i*j < MAX_M; j++){
	prime[i*j] = true;
      }
    }
  }
  
  //grundy数を前計算しておく
  for(int m = 2; m < MAX_M; m++){
    
    if(!prime[m]){
      grundy[m] = 1;
      continue;
    }
    
    //遷移先
    vector<int> L;
    
    for(int n = 0; n < primeList.size() && primeList[n] <= m; n++){
      if(m % primeList[n] == 0){
	L.push_back(m/primeList[n]);
      }
      if(primeList[n] * primeList[n] <= m &&
	 m % (primeList[n] * primeList[n]) == 0){
	L.push_back(m/(primeList[n] * primeList[n]));
      }
    }
    
    set<int> S;
    
    for(int i = 0; i < L.size(); i++){
      S.insert(grundy[L[i]]);
    }

    for(int n = 0; ; n++){
      if(S.find(n) == S.end()){
	grundy[m] = n;
	break;
      }
    }

  }

}

int main(){

  init();

  //入力
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> M[i];
  }

  int ans = 0;
  for(int i = 0; i < N; i++){
    ans ^= grundy[M[i]];
  }

  if(ans != 0)
    cout << "Alice" << endl;
  else
    cout << "Bob" << endl;

  return 0;

}
0