結果

問題 No.526 フィボナッチ数列の第N項をMで割った余りを求める
ユーザー lvs7klvs7k
提出日時 2018-09-15 12:23:24
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 390 bytes
コンパイル時間 8,682 ms
コンパイル使用メモリ 161,916 KB
実行使用メモリ 212,428 KB
最終ジャッジ日時 2023-09-23 03:47:16
合計ジャッジ時間 14,855 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,516 KB
testcase_01 AC 3 ms
7,504 KB
testcase_02 AC 3 ms
7,452 KB
testcase_03 AC 3 ms
7,356 KB
testcase_04 AC 3 ms
7,440 KB
testcase_05 AC 3 ms
7,460 KB
testcase_06 AC 3 ms
7,564 KB
testcase_07 AC 3 ms
7,880 KB
testcase_08 AC 12 ms
12,892 KB
testcase_09 AC 73 ms
26,220 KB
testcase_10 AC 743 ms
212,428 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

module Main where

import Control.Monad
import qualified Data.IntMap.Lazy as M

fiboMod :: Int -> Int -> Int
fiboMod n d = f n
  where
    memo = M.fromList $ fmap (\i -> (i, f i)) [1 .. n]
    f 1 = 0 `mod` d
    f 2 = 1 `mod` d
    f x = (memo M.! (x - 2) + memo M.! (x - 1)) `mod` d

main :: IO ()
main = do
    [n, m] <- fmap read . words <$> getLine :: IO [Int]
    print $ fiboMod n m
0