結果

問題 No.7 プライムナンバーゲーム
ユーザー ScottShelbyScottShelby
提出日時 2020-08-31 20:58:31
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,426 bytes
コンパイル時間 1,635 ms
コンパイル使用メモリ 173,260 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-28 11:09:46
合計ジャッジ時間 2,396 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1000000007;
const int INF = 1001001001;

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};

bool dp[10001];
int main() {
  int n;
  cin >> n;
  Sieve s(10001);
  
  dp[0] = dp[1] = false;
  auto primes = s.primes;
  for (int i = 2; i <= n; ++i) {
    bool win = false;
    rep(j, primes.size()) {
      int prime = primes[j];
      if (prime > i) break;
      win |= dp[i - prime];
    }
    dp[i] = win;
  }

  string ans = (dp[n] ? "Win" : "Lose");
  cout << ans << endl;
}
0