結果

問題 No.7 プライムナンバーゲーム
ユーザー sonotarousonotarou
提出日時 2021-01-07 22:40:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 12 ms / 5,000 ms
コード長 943 bytes
コンパイル時間 1,775 ms
コンパイル使用メモリ 167,548 KB
実行使用メモリ 6,952 KB
最終ジャッジ日時 2024-04-09 05:02:08
合計ジャッジ時間 2,521 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,948 KB
testcase_02 AC 12 ms
6,948 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 5 ms
6,948 KB
testcase_07 AC 3 ms
6,948 KB
testcase_08 AC 3 ms
6,944 KB
testcase_09 AC 6 ms
6,948 KB
testcase_10 AC 1 ms
6,948 KB
testcase_11 AC 4 ms
6,944 KB
testcase_12 AC 9 ms
6,944 KB
testcase_13 AC 9 ms
6,944 KB
testcase_14 AC 11 ms
6,944 KB
testcase_15 AC 12 ms
6,944 KB
testcase_16 AC 11 ms
6,952 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T&a,T b){if(a>b){a=b;return 1;}return 0;}
using ll = long long;

int n;
int dp[100005];
vector<int> ps;

vector< bool > prime_table(int n) {
  vector< bool > prime(n + 1, true);
  if(n >= 0) prime[0] = false;
  if(n >= 1) prime[1] = false;
  for(int i = 2; i * i <= n; i++) {
    if(!prime[i]) continue;
    for(int j = i + i; j <= n; j += i) {
      prime[j] = false;
    }
  }
  return prime;
}

int main(){
    ios::sync_with_stdio(false); 
    cin.tie(0);

    cin >> n;
	vector<bool> v=prime_table(n);
	rep(i,n+1)if(v[i]) ps.push_back(i);

	dp[0]=dp[1]=1;		
	for(int i=2;i<n+1;i++){
		for(auto p : ps){
			if(p>i) break;
			dp[i]|=!dp[i-p];
		}
	}
	cout << (dp[n] ? "Win" : "Lose") << endl;
}
0