結果

問題 No.7 プライムナンバーゲーム
ユーザー motimoti
提出日時 2015-08-01 21:29:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 6 ms / 5,000 ms
コード長 1,062 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 90,088 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 03:48:15
合計ジャッジ時間 1,540 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,948 KB
testcase_02 AC 6 ms
6,948 KB
testcase_03 AC 2 ms
6,948 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 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,948 KB
testcase_11 AC 3 ms
6,944 KB
testcase_12 AC 5 ms
6,944 KB
testcase_13 AC 6 ms
6,944 KB
testcase_14 AC 6 ms
6,948 KB
testcase_15 AC 6 ms
6,952 KB
testcase_16 AC 6 ms
6,948 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 1; }

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

int main() {

  memset(memo, -1, sizeof memo);

  int N;cin >> N;

  fill(pr, pr+10001, 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