結果

問題 No.7 プライムナンバーゲーム
ユーザー rn4rurn4ru
提出日時 2016-04-13 01:19:39
言語 Java21
(openjdk 21)
結果
AC  
実行時間 161 ms / 5,000 ms
コード長 903 bytes
コンパイル時間 2,134 ms
コンパイル使用メモリ 78,004 KB
実行使用メモリ 54,380 KB
最終ジャッジ日時 2024-04-09 03:57:33
合計ジャッジ時間 5,518 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 124 ms
54,012 KB
testcase_01 AC 124 ms
53,912 KB
testcase_02 AC 156 ms
54,296 KB
testcase_03 AC 154 ms
54,060 KB
testcase_04 AC 141 ms
54,132 KB
testcase_05 AC 137 ms
54,304 KB
testcase_06 AC 151 ms
54,312 KB
testcase_07 AC 150 ms
54,080 KB
testcase_08 AC 136 ms
53,220 KB
testcase_09 AC 151 ms
53,920 KB
testcase_10 AC 132 ms
53,796 KB
testcase_11 AC 149 ms
54,076 KB
testcase_12 AC 156 ms
53,968 KB
testcase_13 AC 161 ms
54,112 KB
testcase_14 AC 160 ms
54,220 KB
testcase_15 AC 161 ms
54,036 KB
testcase_16 AC 161 ms
54,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	static List<Integer> sleeve = new ArrayList<>();

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();

		sleeve(N);
		System.out.println(f(N) ? "Win" : "Lose");
	}

	private static void sleeve(int n) {
		boolean s[] = new boolean[n + 1];
		for (int i = 2; i <= n; i++) {
			if (s[i])
				continue;

			for (int j = i * 2; j <= n; j += i) {
				s[j] = true;
			}
		}
		for (int i = 2; i <= n; i++) {
			if (!s[i])
				sleeve.add(i);
		}
	}

	private static boolean f(int n) {
		boolean[] win = new boolean[n + 1];
		for (int i = 0; i <= n; i++) {
			for (int j = 0; j < sleeve.size(); j++) {
				if (i - sleeve.get(j) < 2)
					break;
				if (!win[i - sleeve.get(j)]) {
					win[i] = true;
					break;
				}
			}
		}

		return win[n];
	}

}
0