結果
問題 | No.265 数学のテスト |
ユーザー | ともき |
提出日時 | 2015-08-08 02:10:58 |
言語 | Haskell (9.8.2) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 2,986 bytes |
コンパイル時間 | 1,856 ms |
コンパイル使用メモリ | 175,964 KB |
実行使用メモリ | 11,008 KB |
最終ジャッジ日時 | 2024-05-03 11:50:58 |
合計ジャッジ時間 | 2,990 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 6 ms
8,576 KB |
testcase_01 | AC | 9 ms
10,368 KB |
testcase_02 | AC | 18 ms
11,008 KB |
testcase_03 | AC | 15 ms
9,600 KB |
testcase_04 | AC | 15 ms
9,600 KB |
testcase_05 | AC | 17 ms
9,984 KB |
testcase_06 | AC | 15 ms
9,728 KB |
testcase_07 | AC | 17 ms
9,728 KB |
testcase_08 | AC | 22 ms
10,880 KB |
testcase_09 | AC | 14 ms
9,600 KB |
testcase_10 | AC | 16 ms
9,856 KB |
testcase_11 | AC | 17 ms
10,240 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 8 ms
8,704 KB |
testcase_14 | AC | 6 ms
8,064 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | AC | 4 ms
7,552 KB |
testcase_17 | AC | 1 ms
6,940 KB |
testcase_18 | AC | 1 ms
6,940 KB |
testcase_19 | AC | 2 ms
6,940 KB |
testcase_20 | AC | 1 ms
6,944 KB |
testcase_21 | AC | 2 ms
6,940 KB |
testcase_22 | AC | 6 ms
7,808 KB |
testcase_23 | AC | 1 ms
6,940 KB |
testcase_24 | AC | 1 ms
6,944 KB |
testcase_25 | AC | 9 ms
8,576 KB |
testcase_26 | AC | 1 ms
6,944 KB |
testcase_27 | AC | 1 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 2 ms
6,940 KB |
testcase_30 | AC | 3 ms
6,944 KB |
testcase_31 | AC | 1 ms
6,940 KB |
testcase_32 | AC | 1 ms
6,944 KB |
testcase_33 | AC | 2 ms
6,940 KB |
testcase_34 | AC | 1 ms
6,940 KB |
testcase_35 | AC | 2 ms
6,944 KB |
コンパイルメッセージ
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:83:65: 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." | 83 | eval (Bibun r) = do {k <- eval r; return $ zipWith (*) ((tail k) ++ [0]) [1..]} | ^^^^ [2 of 2] Linking a.out
ソースコード
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-} import Control.Applicative import Control.Monad.Reader 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 -- list size is constant. -- 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 -- eval :: Int -> Exp -> [Int] -- eval m (Con a) = take m (a : [0,0 ..]) -- eval m (Var _) = take m (0 : 1 : [0,0..]) -- eval m (Mult x (Var _)) = 0 : (init (eval m x)) -- eval m (Mult (Var _) x) = 0 : (init (eval m x)) -- eval m (Mult x (Con a)) = map (* a) $ eval m x -- eval m (Mult (Con a) x) = map (* a) $ eval m x -- eval m (Mult _ _) = error "mult" -- eval m (Plus l r) = zipWith (+) (eval m l) (eval m r) -- eval m (Bibun r) = zipWith (*) ((tail $ eval m r) ++ [0]) [1..] -- solve :: Int -> String -> [Int] -- solve max_degree = (eval (max_degree+1)) . parse eval :: Exp -> Reader Int [Int] eval (Con a) = do {m <- ask; return $ take m (a : [0,0 ..])} eval (Var _) = do {m <- ask; return $ take m (0 : 1 : [0,0..])} eval (Mult x (Var _)) = do {r <- eval x; return $ 0 : (init r)} eval (Mult (Var _) x) = do {r <- eval x; return $ 0 : (init r)} eval (Mult x (Con a)) = do {r <- eval x; return $ map (* a) r} eval (Mult (Con a) x) = do {r <- eval x; return $ map (* a) r} eval (Mult _ _) = error "mult" eval (Plus l r) = do {a <- eval l; b <- eval r; return $ zipWith (+) a b} eval (Bibun r) = do {k <- eval r; return $ zipWith (*) ((tail k) ++ [0]) [1..]} solve :: Int -> String -> [Int] solve m s = runReader (eval (parse s)) (m+1) main :: IO () main = do n <- read <$> getLine :: IO Int d <- read <$> getLine :: IO Int s <- getLine putStrLn $ foldl (++) "" (L.intersperse " " (map show (solve d s)))