結果

問題 No.7 プライムナンバーゲーム
ユーザー doyazaki012doyazaki012
提出日時 2015-05-28 14:08:01
言語 Java21
(openjdk 21)
結果
AC  
実行時間 308 ms / 5,000 ms
コード長 1,082 bytes
コンパイル時間 3,005 ms
コンパイル使用メモリ 77,952 KB
実行使用メモリ 56,836 KB
最終ジャッジ日時 2024-04-09 03:46:06
合計ジャッジ時間 7,207 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 140 ms
54,176 KB
testcase_01 AC 143 ms
54,208 KB
testcase_02 AC 195 ms
54,612 KB
testcase_03 AC 149 ms
54,176 KB
testcase_04 AC 155 ms
54,648 KB
testcase_05 AC 152 ms
54,272 KB
testcase_06 AC 193 ms
54,364 KB
testcase_07 AC 178 ms
54,584 KB
testcase_08 AC 164 ms
54,504 KB
testcase_09 AC 223 ms
54,208 KB
testcase_10 AC 141 ms
54,288 KB
testcase_11 AC 184 ms
54,344 KB
testcase_12 AC 269 ms
54,564 KB
testcase_13 AC 270 ms
54,544 KB
testcase_14 AC 308 ms
54,524 KB
testcase_15 AC 308 ms
56,836 KB
testcase_16 AC 292 ms
54,528 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