結果

問題 No.7 プライムナンバーゲーム
ユーザー peilg4peilg4
提出日時 2022-02-11 00:01:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 44 ms / 5,000 ms
コード長 623 bytes
コンパイル時間 1,568 ms
コンパイル使用メモリ 163,604 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-09 05:07:02
合計ジャッジ時間 2,548 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,820 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 44 ms
6,944 KB
testcase_03 AC 4 ms
6,948 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,948 KB
testcase_06 AC 13 ms
6,944 KB
testcase_07 AC 9 ms
6,944 KB
testcase_08 AC 5 ms
6,948 KB
testcase_09 AC 19 ms
6,948 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 31 ms
6,948 KB
testcase_13 AC 33 ms
6,948 KB
testcase_14 AC 43 ms
6,948 KB
testcase_15 AC 41 ms
6,948 KB
testcase_16 AC 37 ms
6,944 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