結果

問題 No.22 括弧の対応
ユーザー matsu7874matsu7874
提出日時 2015-08-14 14:03:02
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 18 ms / 5,000 ms
コード長 376 bytes
コンパイル時間 188 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 8,372 KB
最終ジャッジ日時 2023-09-27 12:56:14
合計ジャッジ時間 1,196 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
8,040 KB
testcase_01 AC 14 ms
8,168 KB
testcase_02 AC 14 ms
8,120 KB
testcase_03 AC 17 ms
8,220 KB
testcase_04 AC 17 ms
8,164 KB
testcase_05 AC 17 ms
8,152 KB
testcase_06 AC 18 ms
8,268 KB
testcase_07 AC 16 ms
8,372 KB
testcase_08 AC 16 ms
8,176 KB
testcase_09 AC 16 ms
8,252 KB
testcase_10 AC 16 ms
8,220 KB
testcase_11 AC 14 ms
8,320 KB
testcase_12 AC 15 ms
8,232 KB
testcase_13 AC 17 ms
8,340 KB
testcase_14 AC 14 ms
8,244 KB
testcase_15 AC 17 ms
8,300 KB
testcase_16 AC 16 ms
8,296 KB
testcase_17 AC 14 ms
8,256 KB
testcase_18 AC 14 ms
8,124 KB
権限があれば一括ダウンロードができます

ソースコード

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):
    if S[i] == '(':
        rank[i] = r
        r += 1
    else:
        r -= 1
        rank[i] = r
# print(rank)
if S[K-1] == '(':
    d = 1
else:
    d = -1
t = K-1+d
while True:
    if rank[K-1] == rank[t]:
        print(t+1)
        exit()
    else:
        t += d
0