結果

問題 No.22 括弧の対応
ユーザー zakuro9715zakuro9715
提出日時 2015-10-08 00:52:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 88 ms / 5,000 ms
コード長 311 bytes
コンパイル時間 279 ms
コンパイル使用メモリ 87,324 KB
実行使用メモリ 82,980 KB
最終ジャッジ日時 2023-09-27 12:56:49
合計ジャッジ時間 2,847 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
71,056 KB
testcase_01 AC 61 ms
71,216 KB
testcase_02 AC 63 ms
71,320 KB
testcase_03 AC 88 ms
82,980 KB
testcase_04 AC 69 ms
76,164 KB
testcase_05 AC 73 ms
76,020 KB
testcase_06 AC 78 ms
76,268 KB
testcase_07 AC 81 ms
76,256 KB
testcase_08 AC 78 ms
76,212 KB
testcase_09 AC 73 ms
76,028 KB
testcase_10 AC 73 ms
76,124 KB
testcase_11 AC 70 ms
76,008 KB
testcase_12 AC 73 ms
75,896 KB
testcase_13 AC 78 ms
76,336 KB
testcase_14 AC 65 ms
75,960 KB
testcase_15 AC 76 ms
76,184 KB
testcase_16 AC 75 ms
76,148 KB
testcase_17 AC 63 ms
71,244 KB
testcase_18 AC 62 ms
71,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, M = map(int, input().split())
s = input()
m = [-1] * N


def f(i):
    if m[i] != -1:
        return m[i]
    st = i
    i += 1
    while i < N and s[i] == '(':
        i = f(i)
        i += 1
    m[i] = st
    m[st] = i
    return i


for i in range(N):
    if s[i] == '(':
        f(i)

print(m[M - 1] + 1)
0