結果

問題 No.22 括弧の対応
ユーザー 佐藤淳平佐藤淳平
提出日時 2019-09-06 11:17:13
言語 Haskell
(9.8.2)
結果
AC  
実行時間 3 ms / 5,000 ms
コード長 673 bytes
コンパイル時間 4,819 ms
コンパイル使用メモリ 164,544 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-09-27 13:41:17
合計ジャッジ時間 2,278 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
7,140 KB
testcase_01 AC 2 ms
7,284 KB
testcase_02 AC 3 ms
7,160 KB
testcase_03 AC 3 ms
7,456 KB
testcase_04 AC 2 ms
7,328 KB
testcase_05 AC 2 ms
7,296 KB
testcase_06 AC 3 ms
7,392 KB
testcase_07 AC 2 ms
7,364 KB
testcase_08 AC 3 ms
7,228 KB
testcase_09 AC 2 ms
7,364 KB
testcase_10 AC 3 ms
7,268 KB
testcase_11 AC 2 ms
7,268 KB
testcase_12 AC 3 ms
7,316 KB
testcase_13 AC 3 ms
7,564 KB
testcase_14 AC 3 ms
7,276 KB
testcase_15 AC 2 ms
7,400 KB
testcase_16 AC 2 ms
7,508 KB
testcase_17 AC 2 ms
7,136 KB
testcase_18 AC 3 ms
7,096 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 Data.ByteString.Char8 (ByteString)
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = solve <$> (map read . words <$> getLine) <*> B.getLine >>= print

solve :: [Int] -> ByteString -> Int
solve [n, k] s = f 1 [] u
    where
        u = B.unpack s
        f i xs (c:cs) = if c == '('
                            then f (i + 1) (i : xs) cs
                            else if head xs == k
                                    then i
                                    else if i == k
                                            then head xs
                                            else f (i + 1) (tail xs) cs
0