結果
| 問題 |
No.420 mod2漸化式
|
| ユーザー |
くれちー
|
| 提出日時 | 2016-12-27 13:06:05 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 524 bytes |
| コンパイル時間 | 14,961 ms |
| コンパイル使用メモリ | 170,496 KB |
| 実行使用メモリ | 400,384 KB |
| 最終ジャッジ日時 | 2024-12-15 02:03:44 |
| 合計ジャッジ時間 | 90,606 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 |
| other | TLE * 35 |
コンパイルメッセージ
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:21:22: 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."
|
21 | putStrLn $ show (head ans) ++ " " ++ show (last ans)
| ^^^^
[2 of 2] Linking a.out
ソースコード
getHalf :: [Int] -> [Int]
getHalf l = drop (length l `div` 2) l
makeList :: Int -> [Int]
makeList 0 = [1]
makeList x = makeList2 (makeList (pred x))
makeList2 :: [Int] -> [Int]
makeList2 l
| length l == 1 = l ++ [succ (last l)]
| otherwise = l ++ makeList2 (getHalf l)
solve :: Int -> [Int]
solve x = [length l, sum l] where
l = filter (== x) (foldr (++) [] (map makeList [0..30]))
main :: IO ()
main = do
x <- readLn
let ans = solve x
putStrLn $ show (head ans) ++ " " ++ show (last ans)
くれちー