結果

問題 No.7 プライムナンバーゲーム
ユーザー GrenacheGrenache
提出日時 2015-07-01 15:04:57
言語 Java21
(openjdk 21)
結果
AC  
実行時間 246 ms / 5,000 ms
コード長 953 bytes
コンパイル時間 3,521 ms
コンパイル使用メモリ 77,828 KB
実行使用メモリ 54,556 KB
最終ジャッジ日時 2024-04-09 03:47:35
合計ジャッジ時間 7,511 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 132 ms
54,172 KB
testcase_01 AC 131 ms
54,212 KB
testcase_02 AC 244 ms
53,988 KB
testcase_03 AC 145 ms
54,204 KB
testcase_04 AC 147 ms
54,140 KB
testcase_05 AC 148 ms
54,296 KB
testcase_06 AC 170 ms
54,100 KB
testcase_07 AC 159 ms
54,368 KB
testcase_08 AC 148 ms
53,992 KB
testcase_09 AC 184 ms
54,556 KB
testcase_10 AC 134 ms
54,204 KB
testcase_11 AC 161 ms
54,016 KB
testcase_12 AC 214 ms
54,328 KB
testcase_13 AC 220 ms
54,300 KB
testcase_14 AC 246 ms
54,076 KB
testcase_15 AC 240 ms
54,492 KB
testcase_16 AC 232 ms
54,236 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Arrays;
import java.util.Scanner;


public class Main_yukicoder7 {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        boolean[] e = new boolean[n + 1];
        Arrays.fill(e, true);
        e[0] = false;
        e[1] = false;
        for (int i = 2; i <= n; i++) {
        	if (e[i]) {
        		for (int j = 2; i * j <= n; j++) {
        			e[i * j] = false;
        		}
        	}
        }

        boolean[] dp = new boolean[n + 1];
        dp[0] = true;
        dp[1] = true;
        for (int i = 2; i <= n; i++) {
        	boolean tmp = false;
        	for (int j = 2; j <= i; j++) {
        		if (e[j]) {
        			tmp |= !dp[i - j];
        		}
        	}
        	dp[i] = tmp;
        }

        if (dp[n]) {
        	System.out.println("Win");
        } else {
        	System.out.println("Lose");
        }
        
        sc.close();
    }
}
0