結果
| 問題 | No.420 mod2漸化式 |
| コンテスト | |
| ユーザー |
くれちー
|
| 提出日時 | 2016-12-27 13:06:05 |
| 言語 | Haskell (9.14.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 524 bytes |
| 記録 | |
| コンパイル時間 | 1,287 ms |
| コンパイル使用メモリ | 195,584 KB |
| 実行使用メモリ | 475,040 KB |
| 最終ジャッジ日時 | 2026-05-25 16:33:06 |
| 合計ジャッジ時間 | 6,064 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | TLE * 1 |
| other | -- * 35 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.14.1/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.Internal.List):
"This is a partial function, it throws an error on empty lists. Use pattern matching, 'Data.List.uncons' or 'Data.Maybe.listToMaybe' 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)
くれちー