結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
mh72012246
|
| 提出日時 | 2016-10-24 15:47:29 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,085 bytes |
| コンパイル時間 | 589 ms |
| コンパイル使用メモリ | 73,964 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 15:49:15 |
| 合計ジャッジ時間 | 1,211 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <sstream> // istringstream
#include <algorithm> // sort
#include <utility> // pair
#include <cfloat> // DBL_MAX
typedef long long ll;
using namespace std;
const int maxN = 10000;
bool ps[maxN-1];
int main(){
int N;
cin >> N;
// is able to win
vector<bool> able (max(N+1,4), false);
able[0] = true; able[1] = true;
// prime (<= N)
vector<int> primes;
for(int i=0; i<N-1; i++){ ps[i] = true; }
for(int i=2; i<sqrt(N)+1; i++){
if(ps[i-2]){
for(int j=i*i; j<=N; j+=i){
ps[j-2] = false;
}
}
}
for(int i=2; i<=N; i++){
if(ps[i-2]){
primes.push_back(i);
}
}
//// main
for(int i=4; i<N+1; i++){
for(uint j=0; j<primes.size(); j++){
if(i <= primes[j]){ // its enough
break;
}
if(!able[i-primes[j]]){ // choice which opp can't win
able[i] = true;
break;
}
}
}
//// main
if(able[N]){
cout << "Win" << endl;
} else {
cout << "Lose" << endl;
}
return 0;
}
mh72012246