結果

問題 No.7 プライムナンバーゲーム
ユーザー doyazaki012doyazaki012
提出日時 2015-05-28 14:08:01
言語 Java19
(openjdk 21)
結果
AC  
実行時間 300 ms / 5,000 ms
コード長 1,082 bytes
コンパイル時間 2,641 ms
コンパイル使用メモリ 73,684 KB
実行使用メモリ 57,592 KB
最終ジャッジ日時 2023-07-24 20:21:22
合計ジャッジ時間 6,395 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
54,108 KB
testcase_01 AC 127 ms
55,632 KB
testcase_02 AC 178 ms
56,180 KB
testcase_03 AC 134 ms
56,100 KB
testcase_04 AC 137 ms
55,804 KB
testcase_05 AC 137 ms
55,820 KB
testcase_06 AC 180 ms
56,124 KB
testcase_07 AC 164 ms
56,248 KB
testcase_08 AC 147 ms
56,112 KB
testcase_09 AC 205 ms
56,328 KB
testcase_10 AC 124 ms
55,828 KB
testcase_11 AC 163 ms
57,592 KB
testcase_12 AC 244 ms
56,376 KB
testcase_13 AC 246 ms
56,236 KB
testcase_14 AC 300 ms
56,284 KB
testcase_15 AC 281 ms
56,240 KB
testcase_16 AC 264 ms
56,000 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Yuki7{
	public static final int DATA_MAX = 11000;
	public static final boolean WIN = true;
	public static final boolean LOSE = false;
	public static boolean[] done = new boolean[DATA_MAX];
	public static boolean[] dp = new boolean[DATA_MAX];
	public static boolean[] prime = new boolean[DATA_MAX];



	static boolean checkWinner(int i){
		if(done[i]==true) return dp[i];
		boolean res = LOSE;
		if(i==0 || i==1){res = WIN;}
		else {
			for(int j=2;j<i;j++){
				if(prime[j]==false && checkWinner(i-j)==LOSE){
					res = WIN;
					break;
				}
			}
		}
		done[i] = true;
		dp[i] = res;
		return res;
	}

	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		for(int i=2;i<=n;i++){
			if(prime[i]==false){
				int j =2;
				while(j*i <= n) {
					prime[j*i] = true;
					j++;
				}
			}
		}
		//for(int i=2;i<n;i++) {if(prime[i]==false) {System.out.println(i);}}
		boolean answer = checkWinner(n);
		if(answer==true){
			System.out.println("Win");
		}
		else{
			System.out.println("Lose");
		}
	}
}
0