結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | zimpha |
提出日時 | 2017-03-24 22:52:50 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 99 ms / 5,000 ms |
コード長 | 2,491 bytes |
コンパイル時間 | 2,636 ms |
コンパイル使用メモリ | 78,652 KB |
実行使用メモリ | 52,364 KB |
最終ジャッジ日時 | 2024-04-09 04:12:33 |
合計ジャッジ時間 | 4,870 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 53 ms
50,324 KB |
testcase_01 | AC | 53 ms
50,444 KB |
testcase_02 | AC | 98 ms
52,364 KB |
testcase_03 | AC | 73 ms
51,488 KB |
testcase_04 | AC | 62 ms
50,580 KB |
testcase_05 | AC | 64 ms
50,416 KB |
testcase_06 | AC | 92 ms
51,864 KB |
testcase_07 | AC | 92 ms
52,008 KB |
testcase_08 | AC | 88 ms
51,392 KB |
testcase_09 | AC | 93 ms
52,176 KB |
testcase_10 | AC | 54 ms
50,568 KB |
testcase_11 | AC | 88 ms
52,112 KB |
testcase_12 | AC | 93 ms
52,108 KB |
testcase_13 | AC | 96 ms
52,240 KB |
testcase_14 | AC | 99 ms
52,156 KB |
testcase_15 | AC | 95 ms
52,268 KB |
testcase_16 | AC | 97 ms
52,200 KB |
ソースコード
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.List; import java.util.StringTokenizer; import java.io.IOException; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author Chiaki.Hoshinomori */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Task007 solver = new Task007(); solver.solve(1, in, out); out.close(); } static class Task007 { public void solve(int testNumber, InputReader in, PrintWriter out) { int n = in.nextInt(); boolean[] mark = new boolean[n + 1]; List<Integer> pl = new ArrayList<>(); for (int i = 2; i <= n; ++i) { if (!mark[i]) { pl.add(i); for (int j = i; j <= n; j += i) { mark[j] = true; } } } mark[0] = mark[1] = true; for (int i = 2; i <= n; ++i) { mark[i] = false; for (int p : pl) { if (p > i) break; if (!mark[i - p]) { mark[i] = true; break; } } } if (mark[n]) out.println("Win"); else out.println("Lose"); } } static class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } } }