結果

問題 No.534 フィボナッチフィボナッチ数
ユーザー tottoripapertottoripaper
提出日時 2017-08-04 21:59:44
言語 Haskell
(9.8.2)
結果
WA  
実行時間 -
コード長 812 bytes
コンパイル時間 1,497 ms
コンパイル使用メモリ 171,776 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-20 02:06:00
合計ジャッジ時間 2,717 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,944 KB
testcase_07 AC 1 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 1 ms
6,940 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 1 ms
6,940 KB
testcase_16 AC 2 ms
6,940 KB
testcase_17 AC 1 ms
6,940 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 2 ms
6,944 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 AC 1 ms
6,944 KB
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 1 ms
6,940 KB
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 AC 2 ms
6,944 KB
testcase_40 AC 1 ms
6,940 KB
testcase_41 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Data.List (transpose)

modulo = 10 ^ 9 + 7

period = 2 * (modulo + 1) `div` 3

fib_mat :: [[Int]]
fib_mat = [[1, 1], [1, 0]]

initial_vector :: [[Int]]
initial_vector = [[0], [1]]

multiply :: (Integral a) => [[a]] -> [[a]] -> a -> [[a]]
multiply a b mo = map (\r -> map ((`mod` mo) . sum . zipWith (*) r) b') a
  where
    b' = transpose b

expt :: [[Int]] -> Int -> Int -> [[Int]]
expt = expt' [[1, 0], [0, 1]]
  where
    expt' a _ 0 _ = a
    expt' a b n mo
      | n `mod` 2 == 1 = expt' (multiply a b mo) b' n' mo
      | otherwise = expt' a b' n' mo
      where
        n' = n `div` 2
        b' = multiply b b mo

main = do
  n <- readLn
  let ([an]:_) = multiply (expt fib_mat n period) initial_vector period
      ([bn]:_) = multiply (expt fib_mat an modulo) initial_vector modulo
  print bn
  
0