結果

問題 No.22 括弧の対応
ユーザー matsu7874matsu7874
提出日時 2015-08-14 14:00:24
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 336 bytes
コンパイル時間 100 ms
コンパイル使用メモリ 10,920 KB
実行使用メモリ 8,352 KB
最終ジャッジ日時 2023-09-25 11:36:51
合計ジャッジ時間 1,378 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,140 KB
testcase_01 AC 15 ms
8,092 KB
testcase_02 AC 16 ms
8,116 KB
testcase_03 AC 19 ms
8,332 KB
testcase_04 AC 17 ms
8,148 KB
testcase_05 AC 17 ms
8,140 KB
testcase_06 AC 18 ms
8,276 KB
testcase_07 WA -
testcase_08 AC 17 ms
8,232 KB
testcase_09 AC 17 ms
8,184 KB
testcase_10 AC 19 ms
8,336 KB
testcase_11 AC 17 ms
8,216 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 19 ms
8,212 KB
testcase_16 AC 18 ms
8,180 KB
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,K = [int(x) for x in input().split()]
S = input()

rank = [0 for i in range(N)]
r = 0
for i in range(N):
    rank[i] = r
    if S[i] == '(':
        r += 1
    else:
        r -= 1
if S[K-1] == '(':
    d = 1
else:
    d = -1
t = K-1+d
while True:
    if rank[K-1] == rank[t]:
        print(t)
        exit()
    else:
        t += d
0