結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー | tak |
提出日時 | 2018-05-25 02:19:38 |
言語 | F# (F# 4.0) |
結果 |
MLE
|
実行時間 | - |
コード長 | 455 bytes |
コンパイル時間 | 4,750 ms |
コンパイル使用メモリ | 165,344 KB |
実行使用メモリ | 572,792 KB |
最終ジャッジ日時 | 2023-09-11 03:19:52 |
合計ジャッジ時間 | 14,317 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 90 ms
25,128 KB |
testcase_01 | AC | 90 ms
23,148 KB |
testcase_02 | AC | 88 ms
23,076 KB |
testcase_03 | AC | 88 ms
22,944 KB |
testcase_04 | AC | 90 ms
23,096 KB |
testcase_05 | AC | 91 ms
23,064 KB |
testcase_06 | AC | 88 ms
21,016 KB |
testcase_07 | AC | 87 ms
25,120 KB |
testcase_08 | AC | 91 ms
24,428 KB |
testcase_09 | AC | 107 ms
35,488 KB |
testcase_10 | AC | 288 ms
135,524 KB |
testcase_11 | MLE | - |
testcase_12 | MLE | - |
testcase_13 | MLE | - |
testcase_14 | MLE | - |
コンパイルメッセージ
Microsoft (R) F# Compiler version 11.0.0.0 for F# 5.0 Copyright (c) Microsoft Corporation. All Rights Reserved. /home/judge/data/code/Main.fs(15,11): warning FS0040: This and other recursive references to the object(s) being defined will be checked for initialization-soundness at runtime through the use of a delayed reference. This is because you are defining one or more recursive objects, rather than recursive functions. This warning may be suppressed by using '#nowarn "40"' or '--nowarn:40'.
ソースコード
let memoize fn = let cache = new System.Collections.Generic.Dictionary<_,_>() (fun x -> match cache.TryGetValue x with | true, v -> v | false, _ -> let v = fn (x) cache.Add(x,v) v) let N,M = let t = stdin.ReadLine().Split() |> Array.map int in t.[0],t.[1] let rec fib = memoize (fun n -> if n <= 1 then 0 elif n = 2 then 1 else (fib (n-1) + fib (n-2)) % M) fib N |> printfn "%i"