結果

問題 No.7 プライムナンバーゲーム
ユーザー ldsybldsyb
提出日時 2016-03-24 17:52:03
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 8 ms / 5,000 ms
コード長 713 bytes
コンパイル時間 460 ms
コンパイル使用メモリ 62,328 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-24 20:32:12
合計ジャッジ時間 1,348 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <numeric>
using namespace std;

#define MAX 10001

vector<int> prime;

void Eratosthenes(){
   bool arr[MAX];
   fill(arr,arr + MAX,false);
   prime.push_back(2);
   for(int i = 4;i < MAX;i += 2) arr[i] = true;
   for(int i = 3;i < MAX;i += 2){
      if(arr[i]) continue;
      prime.push_back(i);
      for(int j = i + i;j < MAX;j += i) arr[j] = true;
   }
}

int main(){
   Eratosthenes();
   bool dp[MAX];
   fill(dp,dp + MAX,false);
   dp[0] = dp[1] = true;
   int n;
   cin >> n;
   for(int i = 2;i <= n;i++){
      for(int j : prime){
         if(i - j < 0) break;
         else dp[i] |= !dp[i - j];
      }
   }
   cout << (dp[n] ? "Win" : "Lose") << endl;
}
0