結果
問題 | No.718 行列のできるフィボナッチ数列道場 (1) |
ユーザー | yuma220284 |
提出日時 | 2019-08-28 09:56:52 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 2,791 bytes |
コンパイル時間 | 2,327 ms |
コンパイル使用メモリ | 172,160 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-11-17 16:09:18 |
合計ジャッジ時間 | 2,428 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 2 ms
5,248 KB |
testcase_05 | AC | 1 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 1 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 2 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 1 ms
5,248 KB |
testcase_14 | AC | 2 ms
5,248 KB |
testcase_15 | AC | 1 ms
5,248 KB |
testcase_16 | AC | 2 ms
5,248 KB |
testcase_17 | AC | 2 ms
5,248 KB |
testcase_18 | AC | 1 ms
5,248 KB |
testcase_19 | AC | 2 ms
5,248 KB |
testcase_20 | AC | 2 ms
5,248 KB |
testcase_21 | AC | 1 ms
5,248 KB |
testcase_22 | AC | 1 ms
5,248 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 ) Main.hs:6:20: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 6 | y = [a | a <- [head b | b <- x]] | ^^^^ Main.hs:7:20: warning: [GHC-63394] [-Wx-partial] In the use of ‘tail’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 7 | z = [a | a <- [tail b | b <- x]] | ^^^^ Main.hs:12:17: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 12 | | otherwise = head x + suml (tail x) | ^^^^ Main.hs:12:32: warning: [GHC-63394] [-Wx-partial] In the use of ‘tail’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Replace it with drop 1, or use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.List.NonEmpty." | 12 | | otherwise = head x + suml (tail x) | ^^^^ Main.hs:18:18: warning: [GHC-63394] [-Wx-partial] In the use of ‘head’ (imported from Prelude, but defined in GHC.List): "This is a partial function, it throws an error on empty lists. Use pattern matching or Data.List.uncons instead. Consider refactoring to use Data.Lis
ソースコード
rotate :: [[Int]] -> [[Int]] rotate x | (x !! 0) == [] = [] | otherwise = y : (rotate z) where y = [a | a <- [head b | b <- x]] z = [a | a <- [tail b | b <- x]] suml :: [Int] -> Int suml x | x == [] = 0 | otherwise = head x + suml (tail x) msuml :: [Int] -> (Int -> Int) msuml x m | m <= 0 = error "modulo is not natural" | x == [] = 0 | otherwise = (head x + (msuml (tail x) m)) `mod` m prod :: [Int] -> ([Int] -> [Int]) prod x y | (length x) /= (length y) = error "Error in prod" | x == [] = [] | otherwise = ((head x) * (head y)) : (prod (tail x) (tail y)) mprod :: [Int] -> ([Int] -> (Int -> [Int])) mprod x y m | m <= 0 = error "modulo is not natural" | (length x) /= (length y) = error "Error int mprod" | x == [] = [] | otherwise = ((head x) * (head y) `mod` m) : (mprod (tail x) (tail y) m) prodsum :: [Int] -> ([Int] -> Int) prodsum x y = suml (prod x y) mprodsum :: [Int] -> ([Int] -> (Int -> Int)) mprodsum x y m | m <= 0 = error "modulo is not natural" | otherwise = msuml (mprod x y m) m mul :: [Int] -> ([[Int]] -> [Int]) mul x y | y == [] = [] | otherwise = (prodsum x (head y)) : (mul x (tail y)) mmul :: [Int] -> ([[Int]] -> (Int -> [Int])) mmul x y m | m <= 0 = error "modulo is not natural" | y == [] = [] | otherwise = (mprodsum x (head y) m) : (mmul x (tail y) m) rotated_matpro :: [[Int]] -> ([[Int]] -> [[Int]]) rotated_matpro x y | x == [] = [] | otherwise = (mul (head x) y) : (rotated_matpro (tail x) y) mrotated_matpro :: [[Int]] -> ([[Int]] -> (Int -> [[Int]])) mrotated_matpro x y m | m <= 0 = error "modulo is not natural" | x == [] = [] | otherwise = (mmul (head x) y m) : (mrotated_matpro (tail x) y m) matpro :: [[Int]] -> ([[Int]] -> [[Int]]) matpro x y = rotated_matpro x (rotate y) mmatpro :: [[Int]] -> ([[Int]] -> (Int -> [[Int]])) mmatpro x y m | m <= 0 = error "modulo is not natural" | otherwise = mrotated_matpro x (rotate y) m repmatpro :: Int -> ([[Int]] -> [[Int]]) repmatpro n x | (length x) /= (length (x !! 0)) = error "Error : matrix is not square" | n < 0 = error "Error : negative pow" | n == 0 = [[1,0],[0,1]] | n == 1 = x | n `mod` 2 == 0 = matpro a a | n `mod` 2 == 1 = matpro x b where a = repmatpro (n `div` 2) x b = repmatpro (n - 1) x mrepmatpro :: Int -> ([[Int]] -> (Int -> [[Int]])) mrepmatpro n x m | m <= 0 = error "modulo is not natural" | n < 0 = error "Error : negative pow" | n == 0 = [[1,0],[0,1]] | n == 1 = x | n `mod` 2 == 0 = mmatpro a a m | n `mod` 2 == 1 = mmatpro x b m where a = mrepmatpro (n `div` 2) x m b = mrepmatpro (n - 1) x m main = do n <- readLn let m = 1000000007 let x = [[1,1],[1,0]] let y = mrepmatpro n x m print $ (((y!!0)!!0) * ((y!!0)!!1)) `mod` m