結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-07-15 02:11:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 10 ms / 5,000 ms |
| コード長 | 1,099 bytes |
| コンパイル時間 | 1,565 ms |
| コンパイル使用メモリ | 168,976 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 16:13:07 |
| 合計ジャッジ時間 | 2,247 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)
void add_mod(ll &a, ll b){
a += b;
a %= MOD;
}
void mul_mod(ll &a, ll b){
a *= b;
a %= MOD;
}
int f(int x){
return (x<10)?x:x%10+f(x/10);
}
vector<int> v;
int l;
bool isp[12345],memo[12345],done[12345];
bool dp(int x){
int i = 0;
if(done[x]){
return memo[x];
}
done[x] = true;
if(x < 2){
memo[x] = true;
return memo[x];
}
memo[x] = false;
for(i=0; i<l; ++i){
if(v[i] > x){
break;
}
if(!dp(x-v[i])){
memo[x] = true;
break;
}
}
return memo[x];
}
int main(void){
int n,i,j;
fill(isp,isp+12345,true);
fill(done,done+12345,false);
isp[0] = false;
isp[1] = false;
for(i=2; i<=123; ++i){
if(!isp[i]){
continue;
}
for(j=i*2; j<=12345; j+=i){
isp[j] = false;
}
}
for(i=2; i<=12345; ++i){
if(isp[i]){
v.push_back(i);
}
}
l = v.l_ength();
cin >> n;
cout << ((dp(n))?"Win":"Lose") << endl;
return 0;
}