結果
| 問題 |
No.457 (^^*)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2018-08-22 16:17:51 |
| 言語 | Haskell (9.10.1) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 924 bytes |
| コンパイル時間 | 6,123 ms |
| コンパイル使用メモリ | 180,160 KB |
| 実行使用メモリ | 820,608 KB |
| 最終ジャッジ日時 | 2024-12-24 05:44:20 |
| 合計ジャッジ時間 | 24,803 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 14 TLE * 5 MLE * 1 |
コンパイルメッセージ
Loaded package environment from /home/judge/.ghc/x86_64-linux-9.8.2/environments/default [1 of 2] Compiling Main ( Main.hs, Main.o ) [2 of 2] Linking a.out
ソースコード
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)