結果

問題 No.7 プライムナンバーゲーム
ユーザー motimoti
提出日時 2015-08-01 21:02:44
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,065 bytes
コンパイル時間 642 ms
コンパイル使用メモリ 91,164 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-25 00:26:31
合計ジャッジ時間 1,746 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>

using namespace std;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)

typedef long long ll;

int memo[10001];
int pr[10001];
int vpr[10001];
int PSIZE;

int solve(int curr) {

  if(curr <= 1) { return 0; }

  int& ret = memo[curr];
  if(ret >= 0) { return ret; }
  ret = 0;
  for(int i=0; i<PSIZE; i++) {
    if(vpr[i] > curr) { break; }
    ret |= !solve(curr - vpr[i]);
  }
  return ret;
}

int main() {

  memset(memo, -1, sizeof memo);

  int N;cin >> N;

  fill(pr, pr+N+1, 1);

  pr[0] = pr[1] = 0;
  for(int i=2; (ll)i*i < N+1; i++)
    if(pr[i])
      for(int j=i*i; j<=N+1; j+=i)
        pr[j] = 0;

  for(int i=0; i<N+1; i++) {
    if(pr[i]) vpr[PSIZE++] = i;
  }

  cout << (solve(N) ? "Win" : "Lose") << endl;

  return 0;
}
0