結果

問題 No.7 プライムナンバーゲーム
ユーザー knkknk
提出日時 2017-09-17 16:32:46
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 890 bytes
コンパイル時間 1,638 ms
コンパイル使用メモリ 166,620 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:23:17
合計ジャッジ時間 2,223 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ul;
typedef signed long long ll;
ul over = 1000000007;

int main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed;
  ll n;
  cin >> n;
  bool isPrime[n+1];
  for (ll i = 0; i <= n; ++i) isPrime[i] = true;
  isPrime[0] = false; isPrime[1] = false;
  vector< ll > PrimeList;
  for (ll piv = 2; piv <= n; ++piv) {
    if (isPrime[piv] == false) continue;
    for (ll amp = 2; piv * amp <= n; ++amp) isPrime[piv * amp] = false;
    PrimeList.push_back(piv);
  }
  PrimeList.push_back(n+1);
  bool isWin[n+1];
  isWin[0] = true; isWin[1] = true;
  for (ll i = 2; i <= n; ++i) {
    bool canWin = false;
    for (ll j = 0; PrimeList[j] <= i; ++j) {
      if (!isWin[i - PrimeList[j]]) {canWin = true; break;}
    }
    isWin[i] = canWin;
  }
  cout << (isWin[n] ? "Win" : "Lose") << endl;
  return 0;
}
0