結果

問題 No.22 括弧の対応
ユーザー flippergoflippergo
提出日時 2021-01-02 10:21:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 42 ms / 5,000 ms
コード長 432 bytes
コンパイル時間 157 ms
コンパイル使用メモリ 82,404 KB
実行使用メモリ 60,516 KB
最終ジャッジ日時 2024-04-20 05:06:32
合計ジャッジ時間 1,605 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
52,280 KB
testcase_01 AC 33 ms
52,736 KB
testcase_02 AC 36 ms
52,232 KB
testcase_03 AC 42 ms
59,608 KB
testcase_04 AC 39 ms
59,292 KB
testcase_05 AC 39 ms
59,964 KB
testcase_06 AC 40 ms
59,948 KB
testcase_07 AC 42 ms
58,676 KB
testcase_08 AC 35 ms
52,688 KB
testcase_09 AC 42 ms
60,480 KB
testcase_10 AC 37 ms
52,340 KB
testcase_11 AC 41 ms
59,500 KB
testcase_12 AC 42 ms
59,772 KB
testcase_13 AC 41 ms
60,516 KB
testcase_14 AC 36 ms
53,248 KB
testcase_15 AC 40 ms
59,356 KB
testcase_16 AC 42 ms
60,512 KB
testcase_17 AC 34 ms
52,912 KB
testcase_18 AC 35 ms
52,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
K -= 1
S = input().strip()
stk = []
for i in range(N):
    if len(stk)>0 and stk[-1][0]=="(":
        if S[i]==")":
            if i==K or stk[-1][1]==K:
                if i==K:
                    print(stk[-1][1]+1)
                else:
                    print(i+1)
                break
            stk.pop()
        else:
            stk.append((S[i],i))
    else:
        stk.append((S[i],i))
0