結果

問題 No.22 括弧の対応
ユーザー gorugo30
提出日時 2021-02-23 15:50:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 47 ms / 5,000 ms
コード長 457 bytes
コンパイル時間 235 ms
コンパイル使用メモリ 82,260 KB
実行使用メモリ 62,736 KB
最終ジャッジ日時 2024-09-22 11:27:06
合計ジャッジ時間 1,874 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

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