結果

問題 No.7 プライムナンバーゲーム
ユーザー Rumain831
提出日時 2025-05-03 02:39:24
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 7 ms / 5,000 ms
コード長 654 bytes
コンパイル時間 976 ms
コンパイル使用メモリ 78,100 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2025-05-03 02:39:26
合計ジャッジ時間 2,190 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 17
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(void){
  int n; cin >> n;
  int nn=10000;
  vector<int> yakusu(nn+1, -1), prime;
  for(int i=2; i<=nn; i++){
    if(yakusu[i]!=-1) continue;
    int copy=i;
    prime.push_back(i);
    while(copy<=nn){
      if(yakusu[copy]==-1) yakusu[copy]=i;
      copy+=i;
    }
  }
  vector<bool> dp(n+1, false);
  dp[0]=dp[1]=true;
  for(int i=3; i<=n; i++){
    for(auto p:prime){
      if(p>i) break;
      if(!dp[i-p]){
        dp[i]=true; break;
      }
    }
  }
  //for(auto p:dp) cout << (p?"W":"L") << ' '; cout << endl;
  cout << (dp[n]?"Win\n":"Lose\n");
  return 0;
}
0