結果

問題 No.7 プライムナンバーゲーム
ユーザー どららどらら
提出日時 2015-05-30 20:57:00
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,366 bytes
コンパイル時間 733 ms
コンパイル使用メモリ 76,492 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-20 17:49:18
合計ジャッジ時間 1,781 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;

#define MAX_PRIME 20000 
bool isprime[MAX_PRIME+1]; 
vector<int> primes; 
void init_prime(){
  fill(isprime, isprime+MAX_PRIME+1, true); 
  isprime[0] = isprime[1] = false; 
  for(int i = 2; i <= MAX_PRIME; i++) { 
    if (isprime[i]) { 
      primes.push_back(i); 
      for(int j = i*2; j <= MAX_PRIME; j += i) 
        isprime[j] = false; 
    } 
  } 
}

int memo[20000];

int solve(int N){
  if(memo[N] >= 0) return memo[N];
  int ret = 0;
  rep(i,primes.size()){
    if(N-primes[i]>=0){
      if(solve(N-primes[i]) == 0){
        ret = 1;
      }else{
        break;
      }
    }
  }
  return memo[N] = ret;
}

int main(){
  init_prime();
  rep(i,20000) memo[i] = -1;

  int N;
  cin >> N;

  memo[0] = 1;
  memo[1] = 1;
  memo[2] = 1;
  memo[3] = 0;
  memo[4] = 0;

  solve(N);
  if(memo[N]>0) cout << "Win" << endl;
  else cout << "Lose" << endl;
  
  return 0;
}
0