結果

問題 No.22 括弧の対応
ユーザー yumenomatayumeyumenomatayume
提出日時 2020-04-04 10:20:41
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 66 ms / 5,000 ms
コード長 427 bytes
コンパイル時間 241 ms
コンパイル使用メモリ 86,856 KB
実行使用メモリ 71,392 KB
最終ジャッジ日時 2023-09-27 13:46:20
合計ジャッジ時間 2,347 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 62 ms
70,972 KB
testcase_01 AC 63 ms
71,068 KB
testcase_02 AC 63 ms
71,140 KB
testcase_03 AC 62 ms
71,360 KB
testcase_04 AC 64 ms
71,092 KB
testcase_05 AC 66 ms
71,048 KB
testcase_06 AC 62 ms
71,136 KB
testcase_07 AC 64 ms
71,352 KB
testcase_08 AC 63 ms
71,320 KB
testcase_09 AC 64 ms
71,164 KB
testcase_10 AC 64 ms
71,100 KB
testcase_11 AC 63 ms
71,316 KB
testcase_12 AC 63 ms
71,124 KB
testcase_13 AC 63 ms
71,136 KB
testcase_14 AC 64 ms
71,100 KB
testcase_15 AC 61 ms
71,068 KB
testcase_16 AC 63 ms
71,204 KB
testcase_17 AC 64 ms
71,392 KB
testcase_18 AC 62 ms
71,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

cnt = 1
if s[k-1] == '(':
    while True:
        if s[k] == '(':
            cnt += 1
        else:
            cnt -=1
        if cnt == 0:
            print(k+1)
            break
        k += 1
else:
    while True:
        if s[k-2] == ')':
            cnt += 1
        else:
            cnt -=1
        if cnt == 0:
            print(k-1)
            break
        k -= 1
0