結果
| 問題 |
No.7 プライムナンバーゲーム
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-08-16 18:50:14 |
| 言語 | Standard ML (MLton 20210117) |
| 結果 |
AC
|
| 実行時間 | 8 ms / 5,000 ms |
| コード長 | 1,400 bytes |
| コンパイル時間 | 3,656 ms |
| コンパイル使用メモリ | 686,980 KB |
| 実行使用メモリ | 7,720 KB |
| 最終ジャッジ日時 | 2025-08-16 18:50:19 |
| 合計ジャッジ時間 | 4,328 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 17 |
ソースコード
fun readInt () =
valOf (TextIO.scanStream (Int.scan StringCvt.DEC) TextIO.stdIn)
fun findPrimes n =
let
fun isPrime i =
let
fun test_loop j =
if i < j * j then true
else if i mod j = 0 then false
else test_loop (j + 1)
in
test_loop 2
end
fun collect current =
if n < current then []
else if isPrime current then current :: collect (current + 1)
else collect (current + 1)
in
collect 2
end
val () =
let
val n = readInt ()
val primes = findPrimes n
val dp = Array.array (n + 1, false)
fun doDp i =
if n < i then ignore ()
else
(
if List.exists (fn p =>
if i < p then false
else Array.sub (dp, i - p) = false)
primes
then Array.update (dp, i, true)
else Array.update (dp, i, false);
doDp (i + 1)
)
in
(
Array.update (dp, 0, true);
Array.update (dp, 1, true);
doDp 2;
if Array.sub (dp, n) = true then print "Win\n"
else print "Lose\n"
)
end