結果
問題 | No.526 フィボナッチ数列の第N項をMで割った余りを求める |
ユーザー | tak |
提出日時 | 2018-08-03 23:00:26 |
言語 | F# (F# 4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 609 bytes |
コンパイル時間 | 11,028 ms |
コンパイル使用メモリ | 194,544 KB |
実行使用メモリ | 56,720 KB |
最終ジャッジ日時 | 2023-10-19 21:37:14 |
合計ジャッジ時間 | 19,141 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge12 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 357 ms
36,748 KB |
testcase_01 | AC | 355 ms
36,760 KB |
testcase_02 | AC | 356 ms
36,760 KB |
testcase_03 | AC | 355 ms
36,756 KB |
testcase_04 | AC | 354 ms
36,760 KB |
testcase_05 | AC | 357 ms
36,760 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | TLE | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
コンパイルメッセージ
復元対象のプロジェクトを決定しています... /home/judge/data/code/main.fsproj を復元しました (288 ms)。 MSBuild のバージョン 17.7.3+8ec440e68 (.NET) /home/judge/data/code/Main.fs(13,17): warning FS0040: 定義されるオブジェクトに対するこの再帰参照および他の再帰参照は、遅延参照を使用して、実行時に初期化の正常性がチェックされます。これは、再帰関数ではなく、1 つまたは複数の再帰オブジェクトを定義しているためです。この警告を抑制するには、'#nowarn "40"' または '--nowarn:40' を使用してください。 [/home/judge/data/code/main.fsproj] main -> /home/judge/data/code/bin/Release/net7.0/main.dll main -> /home/judge/data/code/bin/Release/net7.0/publish/
ソースコード
let memoize f = let memo = System.Collections.Generic.Dictionary<_,_>() (fun x -> match memo.TryGetValue x with | true, v -> v | _ -> let v = f(x) in memo.Add(x,v); v) let rec fib = let modulo = Microsoft.FSharp.Core.int.MaxValue |> int64 let f = function | 0 -> 0L | 1 -> 1L | x -> (fib (x - 1) + fib (x - 2)) % modulo f |> memoize let f n m = let longM = m |> int64 let zeroIndexedN = n - 1 let a = fib zeroIndexedN a % longM let N,M = let t = stdin.ReadLine().Split() |> Array.map int t.[0], t.[1] f N M |> printfn "%i"