結果
問題 | No.7 プライムナンバーゲーム |
ユーザー | pocarist |
提出日時 | 2015-09-11 12:45:17 |
言語 | F# (F# 4.0) |
結果 |
AC
|
実行時間 | 175 ms / 5,000 ms |
コード長 | 1,211 bytes |
コンパイル時間 | 11,763 ms |
コンパイル使用メモリ | 198,408 KB |
実行使用メモリ | 33,024 KB |
最終ジャッジ日時 | 2024-04-09 03:51:15 |
合計ジャッジ時間 | 12,513 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 76 ms
30,592 KB |
testcase_01 | AC | 77 ms
30,592 KB |
testcase_02 | AC | 175 ms
33,024 KB |
testcase_03 | AC | 83 ms
31,320 KB |
testcase_04 | AC | 78 ms
31,224 KB |
testcase_05 | AC | 80 ms
30,968 KB |
testcase_06 | AC | 108 ms
31,616 KB |
testcase_07 | AC | 97 ms
31,616 KB |
testcase_08 | AC | 85 ms
31,232 KB |
testcase_09 | AC | 123 ms
32,384 KB |
testcase_10 | AC | 77 ms
30,848 KB |
testcase_11 | AC | 98 ms
31,488 KB |
testcase_12 | AC | 154 ms
32,984 KB |
testcase_13 | AC | 157 ms
32,896 KB |
testcase_14 | AC | 173 ms
33,024 KB |
testcase_15 | AC | 167 ms
33,024 KB |
testcase_16 | AC | 162 ms
32,768 KB |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (510 ms)。 MSBuild のバージョン 17.9.6+a4ecab324 (.NET) main -> /home/judge/data/code/bin/Release/net8.0/main.dll main -> /home/judge/data/code/bin/Release/net8.0/publish/
ソースコード
// http://yukicoder.me/problems/25 open System let dprintfn fmt = Printf.kprintf Diagnostics.Debug.WriteLine fmt let primes n = let mid = float n |> sqrt |> floor |> int let table = Array.init (n+1) (fun _ -> true) seq { for i in 2 .. mid do if table.[i] then yield i for j in (i+i) .. i .. n do table.[j] <- false for i in (mid+1) .. n do if table.[i] then yield i } [<EntryPoint>] let main argv = let N = Console.ReadLine().Trim() |> int let P = primes N |> List.ofSeq let memo = Array.init (N+1) (fun _ -> None) let rec solve n = if n < 2 then true else match memo.[n] with | Some ans -> ans | None -> P |> List.tryFind (fun p -> if p <= n then not (solve (n-p)) else false) |> function | None -> memo.[n] <- Some false; false | Some ans -> memo.[n] <- Some true; true match solve N with | true -> "Win" | _ -> "Lose" |> printfn "%s" 0