結果

問題 No.7 プライムナンバーゲーム
ユーザー tentententen
提出日時 2020-11-16 18:27:57
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,035 bytes
コンパイル時間 4,248 ms
コンパイル使用メモリ 73,208 KB
実行使用メモリ 58,388 KB
最終ジャッジ日時 2023-09-30 07:25:47
合計ジャッジ時間 6,128 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 103 ms
39,008 KB
testcase_01 WA -
testcase_02 AC 123 ms
40,424 KB
testcase_03 AC 112 ms
39,552 KB
testcase_04 AC 103 ms
39,388 KB
testcase_05 WA -
testcase_06 AC 123 ms
39,540 KB
testcase_07 AC 116 ms
40,196 KB
testcase_08 AC 118 ms
39,588 KB
testcase_09 WA -
testcase_10 AC 130 ms
39,696 KB
testcase_11 AC 137 ms
39,856 KB
testcase_12 AC 129 ms
40,236 KB
testcase_13 AC 127 ms
39,832 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 129 ms
39,820 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("Loose");
        }
    }
}
0