結果

問題 No.7 プライムナンバーゲーム
ユーザー kenta255kenta255
提出日時 2019-11-19 18:27:56
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 828 bytes
コンパイル時間 1,146 ms
コンパイル使用メモリ 109,676 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:45:47
合計ジャッジ時間 1,999 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 3 ms
6,944 KB
testcase_02 AC 6 ms
6,944 KB
testcase_03 AC 3 ms
6,948 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
6,948 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,948 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 4 ms
6,948 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,948 KB
testcase_12 AC 5 ms
6,948 KB
testcase_13 AC 5 ms
6,944 KB
testcase_14 AC 6 ms
6,944 KB
testcase_15 AC 6 ms
6,944 KB
testcase_16 AC 5 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <cmath>
#include <algorithm>
#include <stack>
#include <vector>
#include <random>
#include <queue>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = int(A); I < int(B); ++I)

int memo[10001];
vector<int> p;
// 0 no decide  1lose  2win
// 負けの状態に行ける == 勝ち
int dfs(int x){
  if(memo[x])return memo[x];
  for(int i=0;p[i]<x;i++){
    if(dfs(x-p[i])==1){
      return memo[x] = 2;
    }
  }
  return memo[x] = 1;
}

bool isp(int x){
  for(int i=2;i*i<=x;i++){
    if(x%i==0){
      return false;
    }
  }
  return true;
}

int main(){
  memo[1] = memo[0] = 2;
  memo[2] = memo[3] = 1;
  for(int i=2;i<10001;i++){
    if(isp(i))p.push_back(i);
  }
  p.push_back(1000003);
  int n;
  cin >> n;
  cout << (dfs(n)==1?"Lose":"Win") << endl;
}
0