結果

問題 No.7 プライムナンバーゲーム
ユーザー furafura
提出日時 2020-01-02 17:19:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 5,000 ms
コード長 874 bytes
コンパイル時間 1,951 ms
コンパイル使用メモリ 172,620 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 04:47:23
合計ジャッジ時間 3,243 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 88 ms
6,944 KB
testcase_03 AC 7 ms
6,948 KB
testcase_04 AC 3 ms
6,948 KB
testcase_05 AC 3 ms
6,948 KB
testcase_06 AC 25 ms
6,944 KB
testcase_07 AC 17 ms
6,944 KB
testcase_08 AC 8 ms
6,948 KB
testcase_09 AC 38 ms
6,948 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 18 ms
6,944 KB
testcase_12 AC 62 ms
6,948 KB
testcase_13 AC 66 ms
6,948 KB
testcase_14 AC 89 ms
6,944 KB
testcase_15 AC 83 ms
6,944 KB
testcase_16 AC 77 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class Eratosthenes_sieve{
	vector<bool> er;
	vector<int> p;
public:
	Eratosthenes_sieve(int n):er(n+1,true){
		if(n>=0) er[0]=false;
		if(n>=1) er[1]=false;
		for(int i=2;i*i<=n;i++) if(er[i]) for(int j=i*i;j<=n;j+=i) er[j]=false;
		rep(i,n+1) if(er[i]) p.emplace_back(i);
	}

	bool is_prime(int a)const{
		assert(a<=(int)er.size()-1);
		return a>=0 && er[a];
	}

	const vector<int>& primes()const{ return p; }
};

int main(){
	int n; cin>>n;

	auto P=Eratosthenes_sieve(n).primes();

	vector<int> grundy(n+1),tmp;
	rep(i,n+1){
		tmp.clear();
		for(int p:P){
			if(i-p<2) break;
			tmp.emplace_back(grundy[i-p]);
		}
		sort(tmp.begin(),tmp.end());

		int idx=0;
		rep(a,n+1) if(idx==tmp.size() || tmp[idx]!=a) { grundy[i]=a; break; }
	}
	puts(grundy[n]!=0?"Win":"Lose");

	return 0;
}
0