結果
問題 | No.7 プライムナンバーゲーム |
ユーザー |
![]() |
提出日時 | 2015-10-17 17:03:05 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 79 ms / 5,000 ms |
コード長 | 1,308 bytes |
コンパイル時間 | 797 ms |
コンパイル使用メモリ | 72,168 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-01 15:37:27 |
合計ジャッジ時間 | 1,747 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 17 |
ソースコード
#include <iostream> #include <vector> #include <map> #include <algorithm> #include <cmath> #include <queue> #include <string> #include <cstring> #include <climits> #include <cmath> using namespace std; #define rep(i,n) for(ll i=0;i<n;i++) #define REP(i,x,n) for(ll i=x;i<n;i++) #define ALL(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<":"<<x<<endl #define debug2(x,y) cout<<#x<<":"<<#y<<"=="<<x<<":"<<y<<endl const int INF = INT_MAX / 3; const int dx[] = { 1, 0, -1, 0 }, dy[] = { 0, 1, 0, -1 }; #define MOD 1000000007 typedef pair<int,int> P; typedef long long ll; typedef vector<int> vi; int N; bool sosu[10001]; int memo[2][10001]; //meが0で先手,1で後手。nは受け取る数 bool rec(int me,int n){ if (n == 0 || n == 1) return true; if (memo[me][n] != -1) return memo[me][n]; int next = (me + 1) % 2; for (int i = 0; i < n; i++){ if (sosu[i]){ if (!rec(next, n - i)) return memo[me][n]=true; } } return memo[me][n]=false; } int main(){ cin >> N; rep(i, 10001) sosu[i] = true; sosu[0] = false; sosu[1] = false; memset(memo, -1, sizeof(memo)); for (int i = 2; i <= sqrt(10001); i++){ if (sosu[i]){ for (int j = i * 2; j < 10001; j += i){ sosu[j] = false; } } } if (rec(0, N)){ cout << "Win" << endl; } else{ cout << "Lose" << endl; } return 0; }