結果

問題 No.7 プライムナンバーゲーム
ユーザー wonda_t_coffeewonda_t_coffee
提出日時 2020-02-27 10:16:48
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,274 bytes
コンパイル時間 949 ms
コンパイル使用メモリ 90,636 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 16:47:58
合計ジャッジ時間 5,019 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 WA -
testcase_02 AC 501 ms
6,940 KB
testcase_03 AC 64 ms
6,940 KB
testcase_04 AC 15 ms
6,944 KB
testcase_05 WA -
testcase_06 AC 132 ms
6,940 KB
testcase_07 AC 86 ms
6,944 KB
testcase_08 AC 37 ms
6,944 KB
testcase_09 AC 205 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 87 ms
6,944 KB
testcase_12 AC 346 ms
6,944 KB
testcase_13 AC 369 ms
6,944 KB
testcase_14 WA -
testcase_15 AC 465 ms
6,944 KB
testcase_16 AC 426 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using namespace std;

int n;
map<int, bool> memo;
bool isPrime[10001];

void sieve() {
  for (int i = 0; i <= 10000; i++) isPrime[i] = true;

  isPrime[0] = false;
  isPrime[1] = false;
  for (int i = 4; i <= n; i += 2) {
    isPrime[i] = false;
  }

  int lim = (int)sqrt(n);
  for (int i = 3; i * i <= lim; i += 2) {
    for (int j = 3; i * j <= n; j += 2) {
      isPrime[i * j] = false;
    }
  }
}

int solve(int m) {
  if (memo.find(m) != memo.end()) {
    return memo[m];
  }

  for (int i = 2; i < m; i++) {
    if (!isPrime[i]) continue;

    if (m - i > 1 && !solve(m - i)) {
      memo[m] = true;
      return true;
    }
  }

  memo[m] = false;
  return false;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;

  sieve();
  memo[0] = false;
  memo[1] = false;
  memo[2] = false;

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