結果

問題 No.7 プライムナンバーゲーム
ユーザー tentententen
提出日時 2020-11-16 18:28:38
言語 Java19
(openjdk 21)
結果
AC  
実行時間 155 ms / 5,000 ms
コード長 1,034 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 71,972 KB
実行使用メモリ 56,112 KB
最終ジャッジ日時 2023-07-24 21:41:44
合計ジャッジ時間 5,876 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,092 KB
testcase_01 AC 122 ms
55,384 KB
testcase_02 AC 150 ms
55,744 KB
testcase_03 AC 144 ms
55,800 KB
testcase_04 AC 127 ms
55,408 KB
testcase_05 AC 129 ms
55,432 KB
testcase_06 AC 146 ms
55,740 KB
testcase_07 AC 141 ms
55,608 KB
testcase_08 AC 143 ms
55,572 KB
testcase_09 AC 146 ms
55,692 KB
testcase_10 AC 124 ms
55,300 KB
testcase_11 AC 155 ms
55,524 KB
testcase_12 AC 145 ms
56,112 KB
testcase_13 AC 146 ms
55,576 KB
testcase_14 AC 147 ms
55,528 KB
testcase_15 AC 152 ms
55,852 KB
testcase_16 AC 149 ms
55,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        boolean[] isNotPrime = new boolean[n + 1];
        ArrayList<Integer> primes = new ArrayList<>();
        for (int i = 2; i <= n; i++) {
            if (!isNotPrime[i]) {
                primes.add(i);
                for (int j = 2; j * i <= n; j++) {
                    isNotPrime[i * j] = true;
                }
            }
        }
        boolean[] isWin = new boolean[n + 1];
        isWin[0] = true;
        isWin[1] = true;
        for (int i = 2; i <= n; i++) {
            for (int x : primes) {
                if (x > i) {
                    break;
                }
                if (!isWin[i - x]) {
                    isWin[i] = true;
                    break;
                }
            }
        }
        if (isWin[n]) {
            System.out.println("Win");
        } else {
            System.out.println("Lose");
        }
    }
}
0