結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-01-11 12:27:40 |
| 言語 | D (dmd 2.109.1) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 5,000 ms |
| コード長 | 1,412 bytes |
| コンパイル時間 | 725 ms |
| コンパイル使用メモリ | 107,392 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-06-13 02:35:45 |
| 合計ジャッジ時間 | 1,543 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
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);
}
}
}