結果

問題 No.7 プライムナンバーゲーム
ユーザー kyawashellkyawashell
提出日時 2017-12-08 09:57:49
言語 Java21
(openjdk 21)
結果
AC  
実行時間 151 ms / 5,000 ms
コード長 963 bytes
コンパイル時間 2,031 ms
コンパイル使用メモリ 77,548 KB
実行使用メモリ 54,292 KB
最終ジャッジ日時 2024-04-09 04:24:05
合計ジャッジ時間 5,281 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
53,984 KB
testcase_01 AC 122 ms
54,020 KB
testcase_02 AC 149 ms
53,424 KB
testcase_03 AC 144 ms
54,088 KB
testcase_04 AC 128 ms
53,428 KB
testcase_05 AC 130 ms
54,200 KB
testcase_06 AC 146 ms
54,100 KB
testcase_07 AC 144 ms
53,876 KB
testcase_08 AC 143 ms
54,264 KB
testcase_09 AC 148 ms
54,028 KB
testcase_10 AC 122 ms
54,000 KB
testcase_11 AC 144 ms
54,292 KB
testcase_12 AC 146 ms
54,064 KB
testcase_13 AC 142 ms
54,252 KB
testcase_14 AC 151 ms
53,952 KB
testcase_15 AC 140 ms
53,368 KB
testcase_16 AC 145 ms
53,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

class Main{
	static void gethurui(boolean hurui[],int n){
		hurui[0] = hurui[1] = false;
		for(int i = 2;i <= n;i++)
			hurui[i] = true;
		for(int i = 2;i <= (int)(Math.sqrt(n) + 0.1);i++){
			if(!hurui[i])
				continue;
			for(int j = i * 2;j <= n;j += i){
				hurui[j] = false;
			}
		}
	}
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		scan.close();
		boolean[] hurui = new boolean[n + 1];
		gethurui(hurui,n);

		ArrayList<Integer> p = new ArrayList<Integer>();

		for(int i = 0;i <= n;i++){
			if(hurui[i])
				p.add(i);
		}

		boolean[] dp = new boolean[n + 1];

		dp[0] = dp[1] = true;

		for(int i = 2;i <= n;i++){
			boolean f = false;

			int j = 0;
			while(j < p.size() && p.get(j) <= i){
				if(!dp[i - p.get(j)]){
					f = true;
					break;
				}
				j++;
			}
			dp[i] = f;
		}
		if(dp[n])
			System.out.println("Win");
		else
			System.out.println("Lose");
	}
}
0