結果
問題 | No.12 限定された素数 |
ユーザー | pocarist |
提出日時 | 2015-09-25 18:42:15 |
言語 | F# (F# 4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,403 bytes |
コンパイル時間 | 6,341 ms |
コンパイル使用メモリ | 169,356 KB |
実行使用メモリ | 35,840 KB |
最終ジャッジ日時 | 2023-09-26 15:07:11 |
合計ジャッジ時間 | 32,845 ms |
ジャッジサーバーID (参考情報) |
judge15 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 857 ms
33,788 KB |
testcase_01 | AC | 1,010 ms
33,832 KB |
testcase_02 | AC | 943 ms
33,856 KB |
testcase_03 | WA | - |
testcase_04 | AC | 943 ms
31,892 KB |
testcase_05 | AC | 1,054 ms
33,816 KB |
testcase_06 | AC | 1,050 ms
31,820 KB |
testcase_07 | AC | 1,060 ms
33,780 KB |
testcase_08 | AC | 1,012 ms
31,800 KB |
testcase_09 | AC | 959 ms
33,832 KB |
testcase_10 | AC | 1,063 ms
31,804 KB |
testcase_11 | AC | 1,063 ms
31,768 KB |
testcase_12 | AC | 1,038 ms
33,816 KB |
testcase_13 | AC | 1,027 ms
31,804 KB |
testcase_14 | AC | 1,029 ms
33,884 KB |
testcase_15 | AC | 1,030 ms
33,788 KB |
testcase_16 | AC | 1,115 ms
35,828 KB |
testcase_17 | AC | 856 ms
31,736 KB |
testcase_18 | AC | 859 ms
33,884 KB |
testcase_19 | AC | 852 ms
31,908 KB |
testcase_20 | AC | 957 ms
33,836 KB |
testcase_21 | AC | 1,021 ms
33,824 KB |
testcase_22 | AC | 866 ms
33,964 KB |
testcase_23 | AC | 873 ms
33,848 KB |
testcase_24 | AC | 891 ms
33,872 KB |
testcase_25 | AC | 1,057 ms
35,840 KB |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved.
ソースコード
// http://yukicoder.me/problems/34 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 } let encode x = let rec loop acc n = let m = n % 10 let acc = Set.add m acc let d = n / 10 if d = 0 then acc else loop acc d loop Set.empty x [<EntryPoint>] let main argv = let max_prime = 5000000 let N = Console.ReadLine().Trim() |> int let A = Console.ReadLine().Trim().Split([|' '|]) |> Array.map int |> Set.ofArray primes max_prime |> Seq.fold (fun (start, rest, ans) x -> let X = encode x if Set.difference X A = Set.empty then (start, Set.difference rest X, ans) else let ans = if rest = Set.empty && ans < x-1-start then x-1-start else ans let start = x+1 let rest = A (start, rest, ans) ) (1, A ,-1) |> fun (_, _, ans) -> printfn "%d" ans 0