結果

問題 No.7 プライムナンバーゲーム
ユーザー aaaaasatoriaaaaasatori
提出日時 2018-02-18 14:31:38
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,004 bytes
コンパイル時間 3,131 ms
コンパイル使用メモリ 75,468 KB
実行使用メモリ 57,892 KB
最終ジャッジ日時 2023-09-06 18:20:28
合計ジャッジ時間 8,546 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 231 ms
56,152 KB
testcase_01 WA -
testcase_02 AC 263 ms
56,064 KB
testcase_03 AC 253 ms
55,624 KB
testcase_04 AC 239 ms
55,996 KB
testcase_05 WA -
testcase_06 AC 255 ms
55,792 KB
testcase_07 AC 247 ms
55,684 KB
testcase_08 AC 246 ms
55,948 KB
testcase_09 WA -
testcase_10 AC 230 ms
55,796 KB
testcase_11 AC 247 ms
56,208 KB
testcase_12 AC 253 ms
55,652 KB
testcase_13 AC 254 ms
55,420 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 264 ms
57,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class No7 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean dp[] = new boolean[10010];
		dp[0] = false;
		dp[1] = false;
		dp[2] = false;
		dp[3] = false;
		dp[4] = true;
		dp[5] = true;
		
		List<Integer> sosuu = new ArrayList<Integer>(); //10000以下の素数リスト,要素数1229
		for(int i = 2;i <= 10000;i++) {
			sosuu.add(i);
		}
		for(int i = 0;sosuu.get(i) <= 97;i++) {
			for(int j = sosuu.get(i) * 2;j <= 10000;j += sosuu.get(i)) {
				if(sosuu.indexOf(j) != -1) {
					sosuu.remove(sosuu.indexOf(j));
				}
			}
		}
		
		for(int i = 6;i <= N;i++) {
			for(int j = 0;j < sosuu.size();j++) {
				if(sosuu.get(j) > i) {
					break;
				}
				if(dp[i - sosuu.get(j)] == false) {
					dp[i] = true;
					break;
				}
				dp[i] = false;
			}
		}
		
		if(dp[N]) {
			System.out.println("Win");
		}else {
			System.out.println("Lose");
		}
	}
}
0