結果

問題 No.193 筒の数式
コンテスト
ユーザー ducktail
提出日時 2018-08-03 20:47:04
言語 Haskell
(9.14.1)
コンパイル:
ghc -rtsopts -with-rtsopts=-K1G -o a.out -O2 _filename_
実行:
./a.out
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 707 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 362 ms
コンパイル使用メモリ 165,248 KB
最終ジャッジ日時 2026-05-10 05:07:06
合計ジャッジ時間 988 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
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:5:1: error: [GHC-87110]
    Could not load module ‘Text.Parsec’.
    It is a member of the hidden package ‘parsec-3.1.18.0’.
    Use -v to see a list of the files searched for.
  |
5 | import Text.Parsec (parse, many, many1, eof)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:6:1: error: [GHC-87110]
    Could not load module ‘Text.Parsec.String’.
    It is a member of the hidden package ‘parsec-3.1.18.0’.
    Use -v to see a list of the files searched for.
  |
6 | import Text.Parsec.String (Parser)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Main.hs:7:1: error: [GHC-87110]
    Could not load module ‘Text.Parsec.Char’.
    It is a member of the hidden package ‘parsec-3.1.18.0’.
    Use -v to see a list of the files searched for.
  |
7 | import Text.Parsec.Char (digit, char)
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

ソースコード

diff #
raw source code

import Control.Applicative ((<$>), (<|>))
import Data.List (foldl', tails, inits)
import Data.Either (rights)

import Text.Parsec (parse, many, many1, eof)
import Text.Parsec.String (Parser)
import Text.Parsec.Char (digit, char)

main :: IO ()
main = solve <$> getLine >>= print

solve :: String -> Int
solve s = maximum . rights . map (parse expr "") $ zipWith (++) (tails s) (inits s)

expr :: Parser Int
expr = do
  x <- num
  fs <- many (plus <|> minus)
  eof
  return $ foldl' (\a f -> f a) x fs

num :: Parser Int
num = read <$> many1 digit

plus :: Parser (Int -> Int)
plus = do
  char '+'
  x <- num
  return (+x)

minus :: Parser (Int -> Int)
minus = do
  char '-'
  x <- num
  return (subtract x)
0