結果
| 問題 |
No.534 フィボナッチフィボナッチ数
|
| コンテスト | |
| ユーザー |
yuma220284
|
| 提出日時 | 2019-08-28 09:45:38 |
| 言語 | Haskell (9.10.1) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 2,808 bytes |
| コンパイル時間 | 4,790 ms |
| コンパイル使用メモリ | 172,800 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-17 16:09:01 |
| 合計ジャッジ時間 | 5,660 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 42 |
コンパイルメッセージ
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*2+2)
let z = mrepmatpro ((y!!0)!!1) x m
print $ (z!!0)!!1
yuma220284