結果

問題 No.7 プライムナンバーゲーム
ユーザー uafr_csuafr_cs
提出日時 2015-06-03 14:13:59
言語 Java19
(openjdk 21)
結果
AC  
実行時間 157 ms / 5,000 ms
コード長 960 bytes
コンパイル時間 2,096 ms
コンパイル使用メモリ 74,352 KB
実行使用メモリ 56,340 KB
最終ジャッジ日時 2023-07-24 20:21:44
合計ジャッジ時間 5,586 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 125 ms
55,864 KB
testcase_01 AC 125 ms
55,956 KB
testcase_02 AC 155 ms
56,240 KB
testcase_03 AC 147 ms
56,136 KB
testcase_04 AC 133 ms
55,776 KB
testcase_05 AC 132 ms
55,820 KB
testcase_06 AC 150 ms
56,120 KB
testcase_07 AC 151 ms
56,140 KB
testcase_08 AC 152 ms
56,076 KB
testcase_09 AC 153 ms
56,084 KB
testcase_10 AC 124 ms
55,936 KB
testcase_11 AC 157 ms
56,048 KB
testcase_12 AC 152 ms
55,896 KB
testcase_13 AC 151 ms
55,868 KB
testcase_14 AC 151 ms
56,328 KB
testcase_15 AC 151 ms
56,340 KB
testcase_16 AC 150 ms
56,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
	
		final int N = sc.nextInt();
		boolean[] is_prime = new boolean[N + 1];
		Arrays.fill(is_prime, true);
		is_prime[0] = is_prime[1] = false;
		
		List<Integer> primes = new LinkedList<Integer>();
		
		for(int i = 2; i <= N; i++){
			if(is_prime[i]){
				primes.add(i);
				
				for(int j = i * 2; j <= N; j += i){
					is_prime[j] = false;
				}
			}
		}
		
		boolean[] DP = new boolean[N + 1];
		DP[0] = DP[1] = true;
		for(int i = 2; i <= N; i++){
			boolean only_win = true;
			
			for(final int prime : primes){
				if(prime > i){ break; }
				
				if(!DP[i - prime]){
					only_win = false;
					break;
				}
			}
			
			DP[i] = !only_win;
		}
		
		//System.out.println(Arrays.toString(DP));
		
		System.out.println(DP[N] ? "Win" : "Lose");
	}
	
}
0