結果

問題 No.22 括弧の対応
ユーザー gorugo30gorugo30
提出日時 2021-02-23 15:50:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 51 ms / 5,000 ms
コード長 457 bytes
コンパイル時間 1,113 ms
コンパイル使用メモリ 81,804 KB
実行使用メモリ 61,972 KB
最終ジャッジ日時 2023-10-23 17:30:36
合計ジャッジ時間 3,046 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
53,564 KB
testcase_01 AC 42 ms
53,564 KB
testcase_02 AC 43 ms
53,564 KB
testcase_03 AC 48 ms
61,972 KB
testcase_04 AC 47 ms
59,792 KB
testcase_05 AC 48 ms
59,908 KB
testcase_06 AC 49 ms
61,964 KB
testcase_07 AC 51 ms
61,956 KB
testcase_08 AC 44 ms
55,612 KB
testcase_09 AC 49 ms
61,960 KB
testcase_10 AC 44 ms
55,612 KB
testcase_11 AC 48 ms
59,908 KB
testcase_12 AC 48 ms
61,964 KB
testcase_13 AC 48 ms
61,960 KB
testcase_14 AC 44 ms
55,612 KB
testcase_15 AC 50 ms
61,964 KB
testcase_16 AC 50 ms
61,960 KB
testcase_17 AC 45 ms
53,564 KB
testcase_18 AC 43 ms
53,564 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
from collections import deque
st = deque()
S = input()
K -= 1
for i in range(N):
    if S[i] == ")":
        top = st.pop()
        if top[0] == "(":
            if K == i:
                print(top[1] + 1)
                exit()
            elif K == top[1]:
                print(i + 1)
                exit()
        else:
            st.append(top)
            st.append((S[i], i))
    else:
        st.append((S[i], i))
0