結果

問題 No.22 括弧の対応
ユーザー akitsugu777akitsugu777
提出日時 2019-06-06 10:49:19
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 322 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 11,856 KB
実行使用メモリ 10,340 KB
最終ジャッジ日時 2023-10-25 07:17:45
合計ジャッジ時間 1,507 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,100 KB
testcase_01 AC 27 ms
10,100 KB
testcase_02 AC 28 ms
10,100 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 RE -
testcase_08 WA -
testcase_09 RE -
testcase_10 WA -
testcase_11 WA -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 27 ms
10,100 KB
testcase_18 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
s = list(input())

x = 1
l = []
for i in range(n):
    if s[i] == '(':
        l.append(x)
        x += 1
        
    elif s[i] == ')':
        x -= 1
        l.append(x)

y = l[k-1]

if s[k-1] == '(':
    z = l[y:].index(y)
    print(y + z+1)

else:
    z = l[:y].index(y)
    print(z+1)
0