結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-04-04 23:42:44 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 9 ms / 5,000 ms |
| コード長 | 1,572 bytes |
| コンパイル時間 | 1,230 ms |
| コンパイル使用メモリ | 162,716 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-01 15:31:18 |
| 合計ジャッジ時間 | 1,906 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
#include <bits/stdc++.h>
#define all(x) begin(x),end(x)
#define rall(x) (x).rbegin(),(x).rend()
#define REP(i,b,n) for(int i=(int)(b);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define repsz(i,v) rep(i,(v).size())
#define aur auto&
#define bit(n) (1LL<<(n))
#define eb emplace_back
#define mt make_tuple
#define fst first
#define snd second
using namespace std;
typedef long long ll;
//#define int long long
template<class C>int size(const C &c){ return c.size(); }
template<class T>bool chmin(T&a,const T&b){if(a<=b)return false;a=b;return true;}
template<class T>bool chmax(T&a,const T&b){if(a>=b)return false;a=b;return true;}
vector<int> sieve(int mx){ //{{{
vector<int> f(mx+1);
rep(i, f.size()) f[i] = i;
vector<int> res;
for(int i = 2; i <= mx; ++i){
if(f[i] == i){
res.eb(i);
for(int j = i + i; j <= mx; j += i){
f[j] = 0;
}
}
}
return res;
} //}}}
vector<int> ps;
vector<int> memo;
bool dfs(int n){
int &res = memo[n];
if(res >= 0) return res;
if(n == 0 or n == 1) return res = true;
for(aur p : ps){
if(p > n) break;
if(!dfs(n-p)) return res = true;
}
return res = false;
}
bool solve(){
int n;
cin >> n;
memo.assign(n+10, -1);
ps = sieve(n);
cout << (dfs(n) ? "Win" : "Lose") << endl;
return true;
}
signed main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << std::fixed << std::setprecision(10);
solve();
return 0;
}
// vim:set foldmethod=marker commentstring=//%s: