結果

問題 No.7 プライムナンバーゲーム
ユーザー kk
提出日時 2014-10-29 14:40:50
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 953 bytes
コンパイル時間 555 ms
コンパイル使用メモリ 70,660 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-28 23:03:24
合計ジャッジ時間 1,470 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <string>
#include <cstring>

using namespace std;

bool not_prime[10001];
int memo[10001];
bool rec(int i) {
  if (i == 0) return false;
  if (i == 1) return true;
  if (memo[i] != -1) return memo[i];

  for (int j = i; j >= 1; j--) {
    if (not_prime[j]) continue;
    if (!rec(i-j)) return memo[i]=true;
  }

  return memo[i]=false;
}

int main() {
  int n;
  cin >> n;
  memset(not_prime, false, sizeof(not_prime));
  memset(memo, -1, sizeof(memo));
  not_prime[1] = true;
  for (int i = 2; i <= n; i++) {
    for (int j = i+i; j <= n; j+=i) {
      not_prime[j] = true;
    }
  }

  if (rec(n)) {
    cout << "Win" << endl;
  }else {
    cout << "Lose" << endl;
  }
}
0