結果

問題 No.7 プライムナンバーゲーム
ユーザー shop_oneshop_one
提出日時 2020-04-15 14:52:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,086 bytes
コンパイル時間 1,026 ms
コンパイル使用メモリ 97,760 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:51:23
合計ジャッジ時間 1,855 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 6 ms
6,948 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 2 ms
6,948 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 4 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,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 3 ms
6,948 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 5 ms
6,948 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 #

// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using TP = tuple<ll,ll,ll>;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(18);
}
bool dp[11000];
bool used[11000]={};
vector<ll> prime;
vector<ll> eratos(int max){
  vector<ll> res;
  vector<bool> cp_list(max+1,true);
  cp_list[0]=false;
  cp_list[1]=false;
  for(ll i=2;i<=max;i++){
    if(cp_list[i]){
      res.push_back(i);
      for(ll j=2;j*i<=max;j++){
        cp_list[i*j]=false;
      }
    }
  }
  return res;
}
bool solve(ll n){
  if(used[n]) return dp[n];
  used[n] = true;
  if(n==0||n==1){
    return dp[n] = true;
  }else{
    for(auto i:prime){
      if(i>n) break;
      if(!solve(n-i)){
        return dp[n] = true;
      }
    }
    return false;
  }
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  prime = eratos(n);
  solve(n);
  if(dp[n]) cout <<"Win\n";
  else cout <<"Lose\n";
}
0