結果

問題 No.7 プライムナンバーゲーム
ユーザー shinshin
提出日時 2022-05-17 17:34:16
言語 Java21
(openjdk 21)
結果
AC  
実行時間 101 ms / 5,000 ms
コード長 1,024 bytes
コンパイル時間 4,362 ms
コンパイル使用メモリ 79,096 KB
実行使用メモリ 52,232 KB
最終ジャッジ日時 2024-04-09 05:08:20
合計ジャッジ時間 6,524 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 50 ms
50,316 KB
testcase_01 AC 50 ms
50,516 KB
testcase_02 AC 89 ms
52,052 KB
testcase_03 AC 63 ms
50,536 KB
testcase_04 AC 54 ms
50,256 KB
testcase_05 AC 54 ms
50,316 KB
testcase_06 AC 83 ms
51,284 KB
testcase_07 AC 83 ms
51,436 KB
testcase_08 AC 67 ms
50,964 KB
testcase_09 AC 90 ms
51,564 KB
testcase_10 AC 51 ms
49,952 KB
testcase_11 AC 82 ms
51,188 KB
testcase_12 AC 85 ms
51,932 KB
testcase_13 AC 88 ms
52,232 KB
testcase_14 AC 87 ms
52,220 KB
testcase_15 AC 101 ms
51,956 KB
testcase_16 AC 87 ms
52,160 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class No7 {

	public static void main(String[] args) throws IOException{
		//プライムナンバー
		int N = Integer.parseInt(readStr()[0]) , i , k;
		int[] w = new int[N+1];
		w[0] = 1;
		w[1] = 1;
		ArrayList<Integer> list = new ArrayList<>();
		
		for(i = 2;i <= N;i++) {
			if(w[i] == 0) {
				list.add(i);
				for(k = 2;k <= N/i;k++) {
					w[i * k] = 1;
				}
			}
			w[i] = 0;
			for(k = list.size() - 1;k >= 0;k--) {
				if(w[i - list.get(k)] == 0) {
					w[i] = 1;
					break;
				}
			}
		}
		System.out.println(w[N] == 1 ? "Win" : "Lose");

	}

	public static String[] readStr() throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		ArrayList<String> list = new ArrayList<>();

		do {
			list.add(br.readLine());
		}while(br.ready());

		br.close();

		String[] text = new String[list.size()];
		list.toArray(text);

		return text;

	}
}
0