結果

問題 No.22 括弧の対応
ユーザー zombietanzombietan
提出日時 2016-04-29 00:36:50
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 29 ms / 5,000 ms
コード長 374 bytes
コンパイル時間 654 ms
コンパイル使用メモリ 10,848 KB
実行使用メモリ 9,588 KB
最終ジャッジ日時 2023-09-27 13:04:44
合計ジャッジ時間 1,311 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 21 ms
9,164 KB
testcase_01 AC 23 ms
9,040 KB
testcase_02 AC 24 ms
9,200 KB
testcase_03 AC 29 ms
9,440 KB
testcase_04 AC 23 ms
9,340 KB
testcase_05 AC 22 ms
9,268 KB
testcase_06 AC 25 ms
9,356 KB
testcase_07 AC 24 ms
9,396 KB
testcase_08 AC 23 ms
9,292 KB
testcase_09 AC 25 ms
9,232 KB
testcase_10 AC 23 ms
9,388 KB
testcase_11 AC 23 ms
9,348 KB
testcase_12 AC 24 ms
9,340 KB
testcase_13 AC 27 ms
9,572 KB
testcase_14 AC 21 ms
9,144 KB
testcase_15 AC 25 ms
9,544 KB
testcase_16 AC 26 ms
9,588 KB
testcase_17 AC 21 ms
9,152 KB
testcase_18 AC 21 ms
9,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import re
N,K = map(int,input().split())
S = input()

num = [x for x in range(1,N+1)]
pattern = r"\(\)"
pat = re.compile(pattern)

while True:
    match = pat.search(S)
    s = match.start()
    e = match.end()
    if num[s] == K:
        print(num[e-1])
        break
    elif num[e-1] == K:
        print(num[s])
        break
    del num[s:e]
    S = S.replace('()','',1)
0