結果
| 問題 |
No.40 多項式の割り算
|
| コンテスト | |
| ユーザー |
kou_kkk
|
| 提出日時 | 2025-07-17 00:24:36 |
| 言語 | Haskell (9.10.1) |
| 結果 |
MLE
|
| 実行時間 | - |
| コード長 | 672 bytes |
| コンパイル時間 | 5,670 ms |
| コンパイル使用メモリ | 181,760 KB |
| 実行使用メモリ | 823,072 KB |
| 最終ジャッジ日時 | 2025-07-17 00:24:52 |
| 合計ジャッジ時間 | 13,422 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 1 MLE * 1 -- * 30 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.10.1/environments/default
[1 of 2] Compiling Main ( Main.hs, Main.o )
Main.hs:28:11: warning: [GHC-63394] [-Wx-partial]
In the use of ‘tail’
(imported from Prelude, but defined in GHC.Internal.List):
"This is a partial function, it throws an error on empty lists. Replace it with 'drop' 1, or use pattern matching or 'GHC.Internal.Data.List.uncons' instead. Consider refactoring to use "Data.List.NonEmpty"."
|
28 | calc ns = tail $ zipWith (-) ns $ map (* (head ns)) m
| ^^^^
Main.hs:28:43: 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"."
|
28 | calc ns = tail $ zipWith (-) ns $ map (* (head ns)) m
| ^^^^
[2 of 2] Linking a.out
ソースコード
module Main where
main :: IO ()
main = do
_ <- getLine
a <- getIntList
mapM_ putStrLn $ solve a
m :: [Int]
m = [1, 0, -1, 0] ++ [0, 0 ..]
solve :: [Int] -> [String]
solve a = fmt . loop $ reverse a
where
loop a' | length a' < 4 = a'
| length a' == 4 = calc a'
| otherwise = loop $ calc a'
fmt :: [Int] -> [String]
fmt ns | ns' == [] = ["0", "0"]
| otherwise = [s1, s2]
where
ns' = dropWhile (==0) ns
s1 = show . pred $ length ns'
s2 = unwords . reverse $ map show ns'
calc :: [Int] -> [Int]
calc ns = tail $ zipWith (-) ns $ map (* (head ns)) m
getIntList :: IO [Int]
getIntList = map read . words <$> getLine
kou_kkk