結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
y_mazun
|
| 提出日時 | 2015-04-17 02:44:32 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 22 ms / 5,000 ms |
| コード長 | 1,086 bytes |
| コンパイル時間 | 411 ms |
| コンパイル使用メモリ | 48,128 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-10-01 15:30:34 |
| 合計ジャッジ時間 | 1,194 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
コンパイルメッセージ
main.cpp: In function ‘int getInt()’:
main.cpp:9:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
9 | inline int getInt(){ int s; scanf("%d", &s); return s; }
| ~~~~~^~~~~~~~~~
ソースコード
#include <cstdio>
#include <cstring>
#include <cassert>
#include <queue>
#include <set>
using namespace std;
inline int getInt(){ int s; scanf("%d", &s); return s; }
template<int m>
class Prime{
std::vector<bool> p;
std::vector<int> ps;
public:
Prime(){
p = std::vector<bool>(m,true);
assert(m>1);
p[0]=p[1]=false;
for(int i=4;i<m;i+=2)
p[i]=false;
ps.push_back(2);
for(int i=3;i<m;i+=2){
if(p[i]){
ps.push_back(i);
for(int j=i+i;j<m;j+=i)
p[j]=false;
}
}
}
bool isPrime(int n){
assert(m>n);
return p[n];
}
int operator [] (int n){
if(n<ps.size()) return ps[n];
else return 0;
}
int size(){
return ps.size();
}
};
Prime<10000 + 1> p;
int dp[10000 + 1];
bool solve(int n){
if(n <= 1) return true;
if(dp[n] != -1) return dp[n];
bool ret = false;
for(int i = 0; p[i] <= n && i < p.size(); i++){
if(!solve(n - p[i])) ret = true;
}
return dp[n] = ret;
}
int main(){
memset(dp, -1, sizeof(dp));
puts(solve(getInt()) ? "Win" : "Lose");
return 0;
}
y_mazun