結果

問題 No.457 (^^*)
ユーザー okadukiokaduki
提出日時 2016-12-15 00:59:19
言語 Haskell
(9.8.2)
結果
AC  
実行時間 1,293 ms / 2,000 ms
コード長 1,145 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 161,696 KB
実行使用メモリ 13,804 KB
最終ジャッジ日時 2023-08-20 07:22:45
合計ジャッジ時間 9,638 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,452 KB
testcase_01 AC 3 ms
7,464 KB
testcase_02 AC 3 ms
7,376 KB
testcase_03 AC 3 ms
7,404 KB
testcase_04 AC 3 ms
7,528 KB
testcase_05 AC 3 ms
7,428 KB
testcase_06 AC 3 ms
7,460 KB
testcase_07 AC 3 ms
7,764 KB
testcase_08 AC 3 ms
7,944 KB
testcase_09 AC 4 ms
8,492 KB
testcase_10 AC 6 ms
9,628 KB
testcase_11 AC 12 ms
11,800 KB
testcase_12 AC 853 ms
13,424 KB
testcase_13 AC 642 ms
12,452 KB
testcase_14 AC 1,293 ms
13,804 KB
testcase_15 AC 893 ms
13,452 KB
testcase_16 AC 1,293 ms
13,488 KB
testcase_17 AC 653 ms
12,304 KB
testcase_18 AC 3 ms
7,328 KB
testcase_19 AC 3 ms
7,460 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Control.Monad
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)
import Text.Printf
import Debug.Trace

calcr :: [Integer] -> B.ByteString -> Integer -> Integer
calcr (r:rs) s acc = if s == B.empty then acc
                     else calcr rs bs (if B.head s == '('
                                        then acc + sub rs bs 0
                                        else  acc)
  where
    bs = B.tail s
    sub rs s lv = if s == B.empty then 0
                  else case lv of
                         3 -> head rs
                         0 -> sub (tail rs) (B.tail s)
                           (if B.head s == '*' then lv+1 else lv)
                         _ -> sub (tail rs) (B.tail s)
                              (if B.head s == '^' then lv+1 else lv)

calcacc = B.foldr (\c acc -> (head acc + if c == ')' then 1 else 0):acc) [0]
rev = B.map (\c -> case c of
                     '(' -> ')'
                     ')' -> '('
                     _ -> c) . B.reverse

main = do
  s <- B.getLine
  let rs = rev s
  printf "%d %d\n" (calcr (calcacc rs) rs 0) (calcr (calcacc s) s 0)
0