結果

問題 No.7 プライムナンバーゲーム
ユーザー peilg4peilg4
提出日時 2022-02-11 00:01:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 40 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 1,340 ms
コンパイル使用メモリ 165,488 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-07-24 21:50:22
合計ジャッジ時間 2,398 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
#include <climits>
using namespace std;

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

    bool IsWin[100001]; 
    bool dp[100001]; 
	
	fill(dp,dp+sizeof(dp),true);
	for(int i=0;i<2;i++){
        dp[i]=false;
    }
	for(int i=0;i<4;i++){
        IsWin[i]=false;
    }
	dp[2]=true;
	
	for(int i=3;i<=n;i++){
		for(int j=2;j*j<=i;j++){
			if(dp[j]){
				if(i%j){
					continue;
				}else{
					dp[i]=false;
				}
			}
		} 
	}
	
	for(int i=4;i<=n;i++){
		for(int j=2;j<=i-2;j++){
			if(dp[j] && !IsWin[i-j]){ 
				IsWin[i]=true;
				break;
			}
		}
	}
	
	cout << (IsWin[n]?"Win":"Lose") << endl;
	
	return 0;
}
0