結果

問題 No.22 括弧の対応
ユーザー osrgy01
提出日時 2021-02-03 10:27:05
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 5,000 ms
コード長 458 bytes
コンパイル時間 82 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-06-30 00:13:26
合計ジャッジ時間 1,541 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k=map(int,input().split())
s=[(i+1,j) for i,j in enumerate(input())]
stack=[]
if s[k-1][1]=='(':
    for i,j in s:
        if j=='(':
            stack.append(i)
        else:
            n=stack.pop()
            if n==k:
                print(i)
                exit()
else:
    for i,j in s:
        if j=='(':
            stack.append(i)
        else:
            if i==k:
                print(stack[-1])
                exit()
            stack.pop()
0