結果

問題 No.22 括弧の対応
ユーザー aimyaimy
提出日時 2017-04-17 11:14:06
言語 Haskell
(9.8.2)
結果
AC  
実行時間 4 ms / 5,000 ms
コード長 332 bytes
コンパイル時間 4,672 ms
コンパイル使用メモリ 165,044 KB
実行使用メモリ 9,264 KB
最終ジャッジ日時 2023-09-27 13:14:56
合計ジャッジ時間 2,679 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
7,132 KB
testcase_01 AC 3 ms
7,160 KB
testcase_02 AC 2 ms
7,132 KB
testcase_03 AC 4 ms
9,264 KB
testcase_04 AC 3 ms
8,016 KB
testcase_05 AC 3 ms
7,948 KB
testcase_06 AC 4 ms
8,472 KB
testcase_07 AC 4 ms
8,752 KB
testcase_08 AC 4 ms
8,304 KB
testcase_09 AC 4 ms
8,108 KB
testcase_10 AC 4 ms
8,616 KB
testcase_11 AC 3 ms
8,016 KB
testcase_12 AC 4 ms
8,224 KB
testcase_13 AC 4 ms
8,648 KB
testcase_14 AC 3 ms
7,400 KB
testcase_15 AC 4 ms
9,052 KB
testcase_16 AC 4 ms
8,920 KB
testcase_17 AC 3 ms
7,160 KB
testcase_18 AC 2 ms
7,056 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 Data.List

main = do
 [_,k] <- map read . words <$> getLine
 bs <- getLine
 print (bracket k bs)

bracket :: Int -> String -> Int
bracket k = head . delete k . concat . filter (elem k) . fst . foldr idx ([],[]) . zip [1..]
 where
  idx (i,'(') (acc,((j,')'):stack)) = ([i,j]:acc, stack)
  idx ib (acc,stack) = (acc, ib:stack)
0