結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | nanae |
提出日時 | 2019-01-11 12:27:40 |
言語 | D (dmd 2.106.1) |
結果 |
AC
|
実行時間 | 6 ms / 5,000 ms |
コード長 | 1,412 bytes |
コンパイル時間 | 616 ms |
コンパイル使用メモリ | 95,376 KB |
実行使用メモリ | 4,380 KB |
最終ジャッジ日時 | 2023-09-03 21:56:55 |
合計ジャッジ時間 | 1,743 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 5 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 1 ms
4,376 KB |
testcase_05 | AC | 1 ms
4,376 KB |
testcase_06 | AC | 3 ms
4,376 KB |
testcase_07 | AC | 2 ms
4,376 KB |
testcase_08 | AC | 1 ms
4,376 KB |
testcase_09 | AC | 3 ms
4,380 KB |
testcase_10 | AC | 1 ms
4,376 KB |
testcase_11 | AC | 2 ms
4,376 KB |
testcase_12 | AC | 4 ms
4,380 KB |
testcase_13 | AC | 5 ms
4,380 KB |
testcase_14 | AC | 6 ms
4,380 KB |
testcase_15 | AC | 5 ms
4,380 KB |
testcase_16 | AC | 4 ms
4,376 KB |
ソースコード
import std.stdio, std.string, std.conv; import std.range, std.algorithm, std.array, std.typecons, std.container; import std.math, std.numeric, core.bitop; void main() { int N; scan(N); auto primes = eratos(N + 1); auto dp = new int[](N + 1); dp[0] = dp[1] = 1; foreach (i ; 2 .. N + 1) { dp[i] = 0; foreach (p ; primes) { if (i - p < 0) { break; } if (!dp[i - p]) { dp[i] = 1; break; } } } writeln(dp[N] ? "Win" : "Lose"); } int[] eratos(int N) { auto s = new bool[](N); s[] = true; s[0] = s[1] = false; for (int p = 2; p*p < N; p++) { if (!s[p]) continue; for (int d = p*p; d < N; d += p) { s[d] = false; } } return iota(N).filter!(i => s[i]).array; } void scan(T...)(ref T args) { import std.stdio : readln; import std.algorithm : splitter; import std.conv : to; import std.range.primitives; auto line = readln().splitter(); foreach (ref arg; args) { arg = line.front.to!(typeof(arg)); line.popFront(); } assert(line.empty); } void fillAll(R, T)(ref R arr, T value) { static if (is(typeof(arr[] = value))) { arr[] = value; } else { foreach (ref e; arr) { fillAll(e, value); } } }