結果

問題 No.7 プライムナンバーゲーム
ユーザー xxxasdfghjkxxxasdfghjk
提出日時 2018-08-13 23:01:24
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 17 ms / 5,000 ms
コード長 1,441 bytes
コンパイル時間 697 ms
コンパイル使用メモリ 75,096 KB
実行使用メモリ 4,388 KB
最終ジャッジ日時 2023-07-24 21:11:21
合計ジャッジ時間 1,514 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<cstdio>
#include<queue>
#include<utility>
#include<cstring>
#include<stack>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<map>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int n;
bool primes[10001];
vector<int> p(0);
void setprime(){
  fill(primes,primes+10001,true);
  for(int i=2;i<10001;i++){
    if(primes[i])
      for(int j=i+i;j<10001;j+=i){
        primes[j] = false;
      }
  }
}
int dp[10001][2];
bool solve(int N,int t){
  if(dp[N][t] != -1)
    return dp[N][t];
  if(N == 0 || N == 1){
    if(t)
      return true;
    else
      return false;
  }else{
    for(int i=0;i<p.size();i++){
        if(N-p[i] >= 0){
          if(t == 0){
            if(!solve(N-p[i],1))
              return dp[N][t] = false;
          }else{
            if(solve(N-p[i],0))
              return dp[N][t] = true;
          }
          

          }
      }
  }
  if(t == 0)
    return dp[N][t] = true;
  else
    return dp[N][t] = false;
}
int main()
{
  int N;
  REP(i,10001)REP(j,2)dp[i][j] = -1;
  cin >> N;
  setprime();
  for(int i=2;i<10001;i++){
    if(primes[i]){
      p.push_back(i);  
    }
  }
  
  if(solve(N,1))
    cout << "Win" << endl;
  else
    cout << "Lose" << endl;
  return 0;
}
0