結果

問題 No.7 プライムナンバーゲーム
ユーザー kohaku_kohakukohaku_kohaku
提出日時 2016-12-03 21:18:37
言語 Java21
(openjdk 21)
結果
AC  
実行時間 325 ms / 5,000 ms
コード長 997 bytes
コンパイル時間 2,397 ms
コンパイル使用メモリ 78,064 KB
実行使用メモリ 54,580 KB
最終ジャッジ日時 2024-04-09 04:05:06
合計ジャッジ時間 6,676 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
54,156 KB
testcase_01 AC 135 ms
54,236 KB
testcase_02 AC 302 ms
54,344 KB
testcase_03 AC 149 ms
54,164 KB
testcase_04 AC 144 ms
54,012 KB
testcase_05 AC 144 ms
54,580 KB
testcase_06 AC 193 ms
54,164 KB
testcase_07 AC 161 ms
54,096 KB
testcase_08 AC 154 ms
54,092 KB
testcase_09 AC 227 ms
54,316 KB
testcase_10 AC 129 ms
54,324 KB
testcase_11 AC 164 ms
54,088 KB
testcase_12 AC 269 ms
54,176 KB
testcase_13 AC 278 ms
54,212 KB
testcase_14 AC 325 ms
54,416 KB
testcase_15 AC 310 ms
54,248 KB
testcase_16 AC 296 ms
54,060 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 [] b = new boolean [N+1];
        ArrayList<Integer> prime = new ArrayList<Integer>();
        for(int i=2; i<=N; i++){
            if(b[i]==false){
                prime.add(i);
                for(int j=2; j<=N; j++){
                    if(j%i==0){
                        b[j]=true;
                    }
                }
            }
        }
        boolean [] WL = new boolean [N+1];
        WL[0]=WL[1]=true;
        for(int i=4; i<=N; i++){
            for(int j=prime.size()-1; j>=0; j--){
                if(prime.get(j)<i){
                    if(WL[i-prime.get(j)]==false){
                        WL[i]=true;
                    }
                }
            }
        }
        if(WL[N]){
            System.out.println("Win");
        }else{
            System.out.println("Lose");
        }
    }
}
0