結果

問題 No.22 括弧の対応
ユーザー ysys
提出日時 2018-08-18 09:47:51
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 20 ms / 5,000 ms
コード長 317 bytes
コンパイル時間 85 ms
コンパイル使用メモリ 10,556 KB
実行使用メモリ 8,984 KB
最終ジャッジ日時 2023-09-27 13:28:11
合計ジャッジ時間 1,168 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,924 KB
testcase_01 AC 13 ms
7,848 KB
testcase_02 AC 15 ms
7,860 KB
testcase_03 AC 20 ms
8,896 KB
testcase_04 AC 16 ms
8,400 KB
testcase_05 AC 17 ms
8,444 KB
testcase_06 AC 16 ms
8,780 KB
testcase_07 AC 17 ms
8,708 KB
testcase_08 AC 16 ms
8,724 KB
testcase_09 AC 15 ms
8,540 KB
testcase_10 AC 16 ms
8,652 KB
testcase_11 AC 15 ms
8,472 KB
testcase_12 AC 15 ms
8,736 KB
testcase_13 AC 17 ms
8,840 KB
testcase_14 AC 14 ms
7,916 KB
testcase_15 AC 18 ms
8,984 KB
testcase_16 AC 17 ms
8,816 KB
testcase_17 AC 14 ms
7,920 KB
testcase_18 AC 16 ms
7,808 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
s = input()
st = []
dic1, dic2 = {}, {}
for i in range(n):
    if i + 1 == k:
        t = s[i]
    if s[i] == "(":
        st.insert(0, i)
    else:
        j = st.pop(0)
        dic1[i] = j
        dic2[j] = i

if t == "(":
    print(dic2[k - 1] + 1)
else:
    print(dic1[k - 1] + 1)
0