結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
misora192
|
| 提出日時 | 2020-05-28 22:32:32 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 7 ms / 5,000 ms |
| コード長 | 845 bytes |
| コンパイル時間 | 1,360 ms |
| コンパイル使用メモリ | 171,120 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 16:34:27 |
| 合計ジャッジ時間 | 1,927 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
vector<int> primes;
vector<bool> isprime(n+1, true);
isprime[0] = isprime[1] = false;
for(int i = 2; i <= n; i++){
if(isprime[i]) primes.push_back(i);
for(int j = i * 2; j <= n; j += i) isprime[j] = false;
}
int dp[n+1];
dp[0] = dp[1] = 1;
for(int i = 2; i <= n; i++){
int f = 1;
for(int p : primes){
if(p > i) break;
if(dp[i - p] == 0) f = 0;
}
dp[i] = 1 - f;
}
cout << (dp[n] == 1 ? "Win" : "Lose") << endl;
}
misora192