結果

問題 No.457 (^^*)
ユーザー ducktailducktail
提出日時 2018-08-22 16:17:51
言語 Haskell
(9.8.2)
結果
TLE  
実行時間 -
コード長 924 bytes
コンパイル時間 4,252 ms
コンパイル使用メモリ 164,560 KB
実行使用メモリ 811,860 KB
最終ジャッジ日時 2023-08-25 19:42:57
合計ジャッジ時間 11,365 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,000 KB
testcase_01 AC 3 ms
6,912 KB
testcase_02 AC 2 ms
6,928 KB
testcase_03 AC 2 ms
6,900 KB
testcase_04 AC 3 ms
6,936 KB
testcase_05 AC 2 ms
6,880 KB
testcase_06 AC 3 ms
6,968 KB
testcase_07 AC 4 ms
8,564 KB
testcase_08 AC 12 ms
13,652 KB
testcase_09 AC 52 ms
27,716 KB
testcase_10 AC 404 ms
152,548 KB
testcase_11 TLE -
testcase_12 MLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.6.1/environments/default
[1 of 2] Compiling Main             ( Main.hs, Main.o )
[2 of 2] Linking a.out

ソースコード

diff #

import Control.Applicative
import Data.List
import Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = solve <$> B.getLine >>= putStrLn

solve :: ByteString -> String
solve xs = f $ foldl' count (0,0) (B.tails xs)
  where f (x, y) = unwords . map show $ [x, y]
          
data Face = L0 | L1 | L2 | L3 | R0 | R1 | R2 | R3

left L0 '^' = L1
left L1 '^' = L2
left L2 '*' = L3
left s _ = s

right R0 '*' = R1
right R1 '^' = R2
right R2 '^' = R3
right s _ = s

point L3 = 1
point R3 = 1
point s = 0

count :: (Int, Int) -> ByteString -> (Int, Int)
count (l, r) bs | B.null bs = (l, r)
                | B.head bs == '(' = let (x,y,_,_) = B.foldl' f (l, r, L0, R0) (B.tail bs) in (x, y)
                | otherwise = (l, r)
  where f (cl, cr, sl, sr) c | c == ')' = (cl + point sl, cr + point sr, sl, sr)
                             | otherwise = (cl, cr, left sl c, right sr c)
0