結果
問題 | No.265 数学のテスト |
ユーザー |
![]() |
提出日時 | 2015-08-08 01:35:21 |
言語 | Haskell (9.10.1) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,606 bytes |
コンパイル時間 | 1,959 ms |
コンパイル使用メモリ | 175,304 KB |
実行使用メモリ | 26,040 KB |
最終ジャッジ日時 | 2024-07-18 05:33:34 |
合計ジャッジ時間 | 8,403 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | TLE * 1 -- * 31 |
コンパイルメッセージ
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:37:25: 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." | 37 | (h,k) = expression (tail r) -- remove '{' | ^^^^ Main.hs:38:13: 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." | 38 | a = tail k -- remove '}' | ^^^^ Main.hs:53: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." | 53 | eval (Bibun r) = zipWith (*) (tail $ eval r) [1..] | ^^^^ [2 of 2] Linking a.out
ソースコード
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-} import Control.Applicative import qualified Data.List as L data Exp = Con Int | Var String | Mult Exp Exp | Plus Exp Exp | Bibun Exp deriving (Show) parse :: String -> Exp parse s = case expression s of (a, "") -> a (a, s ) -> error ("remain: " ++ s) expression :: String -> (Exp, String) expression s = case r of '+' : t -> (Plus h k, a) where (k,a) = expression t _ -> (h, r) where (h,r) = term s term :: String -> (Exp, String) term s = case r of '*' : t -> (Mult h k, a) where (k,a) = (term t) _ -> (h, r) where (h,r) = factor s factor :: String -> (Exp, String) factor ('d' : r) = (Bibun h, a) where (h,k) = expression (tail r) -- remove '{' a = tail k -- remove '}' factor ('x' : r) = (Var "x", r) factor s = (Con x, r) where [(x,r)] = reads s eval :: Exp -> [Int] eval (Con a) = a : [0,0 ..] eval (Var _) = 0 : 1 : [0,0..] eval (Mult x (Var _)) = 0 : (eval x) eval (Mult x (Con a)) = map (* a) $ eval x eval (Mult (Var _) x) = 0 : (eval x) eval (Mult (Con a) x) = map (* a) $ eval x eval (Mult _ _) = error "mult" eval (Plus l r) = zipWith (+) (eval l) (eval r) eval (Bibun r) = zipWith (*) (tail $ eval r) [1..] solve :: Int -> String -> [Int] solve max_degree = (take (max_degree+1)) . eval . parse main :: IO () main = do n <- read <$> getLine :: IO Int d <- read <$> getLine :: IO Int s <- getLine putStrLn $ foldr (++) "" (L.intersperse " " (map show (solve d s)))