結果

問題 No.314 ケンケンパ
ユーザー lvs7klvs7k
提出日時 2018-11-08 21:10:19
言語 Haskell
(9.8.2)
結果
AC  
実行時間 793 ms / 1,000 ms
コード長 666 bytes
コンパイル時間 8,351 ms
コンパイル使用メモリ 176,516 KB
実行使用メモリ 257,024 KB
最終ジャッジ日時 2023-08-13 04:25:29
合計ジャッジ時間 13,072 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 784 ms
256,856 KB
testcase_01 AC 3 ms
6,752 KB
testcase_02 AC 3 ms
6,776 KB
testcase_03 AC 2 ms
6,700 KB
testcase_04 AC 3 ms
6,716 KB
testcase_05 AC 2 ms
6,640 KB
testcase_06 AC 3 ms
6,692 KB
testcase_07 AC 3 ms
6,724 KB
testcase_08 AC 3 ms
6,692 KB
testcase_09 AC 3 ms
6,716 KB
testcase_10 AC 3 ms
6,812 KB
testcase_11 AC 3 ms
6,968 KB
testcase_12 AC 3 ms
7,088 KB
testcase_13 AC 3 ms
6,884 KB
testcase_14 AC 4 ms
8,344 KB
testcase_15 AC 5 ms
9,424 KB
testcase_16 AC 22 ms
14,864 KB
testcase_17 AC 72 ms
36,004 KB
testcase_18 AC 443 ms
175,024 KB
testcase_19 AC 793 ms
257,024 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 #

{-# LANGUAGE BangPatterns #-}

import Control.Applicative
import Control.Monad
import Data.List
import Debug.Trace (traceShow)
import qualified Data.ByteString.Char8 as B

import Data.Array

inf :: Int
inf = 10 ^ 9 + 7

solve :: Int -> Int
solve n = (memo ! (n, 0) + memo ! (n, 1) + memo ! (n, 2)) `mod` inf
  where
    memo :: Array (Int, Int) Int
    memo = listArray ((1, 0), (n, 2)) [go i j | i <- [1 .. n], j <- [0 .. 2]]

    go 1 0 = 0
    go 1 1 = 1
    go 1 2 = 0
    go i 0 = memo ! (i - 1, 1) `mod` inf + memo ! (i - 1, 2) `mod` inf
    go i 1 = memo ! (i - 1, 0)
    go i 2 = memo ! (i - 1, 1)

main :: IO ()
main = do
    n <- readLn
    print $ solve n
0