結果

問題 No.22 括弧の対応
ユーザー kohei2019kohei2019
提出日時 2021-02-10 11:35:06
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 90 ms / 5,000 ms
コード長 327 bytes
コンパイル時間 331 ms
コンパイル使用メモリ 87,044 KB
実行使用メモリ 76,512 KB
最終ジャッジ日時 2023-09-22 04:53:42
合計ジャッジ時間 3,050 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 80 ms
71,460 KB
testcase_01 AC 80 ms
71,580 KB
testcase_02 AC 78 ms
71,356 KB
testcase_03 AC 90 ms
76,384 KB
testcase_04 AC 85 ms
76,504 KB
testcase_05 AC 86 ms
76,472 KB
testcase_06 AC 84 ms
76,320 KB
testcase_07 AC 84 ms
76,512 KB
testcase_08 AC 83 ms
76,352 KB
testcase_09 AC 87 ms
76,188 KB
testcase_10 AC 84 ms
76,488 KB
testcase_11 AC 85 ms
76,504 KB
testcase_12 AC 85 ms
76,212 KB
testcase_13 AC 89 ms
76,336 KB
testcase_14 AC 84 ms
75,896 KB
testcase_15 AC 87 ms
76,192 KB
testcase_16 AC 83 ms
76,252 KB
testcase_17 AC 77 ms
71,324 KB
testcase_18 AC 77 ms
71,288 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = map(int,input().split())
S = list(input())
ls = []
pair = [-1]*(N)
for i in range(N):
    ls.append((S[i],i))
    if len(ls) >= 2:
        if ls[-1][0] == ')' and ls[-2][0] == '(':
            pair[ls[-1][1]] = ls[-2][1]
            pair[ls[-2][1]] = ls[-1][1]
            ls.pop()
            ls.pop()
print(pair[K-1]+1)
0