結果

問題 No.22 括弧の対応
ユーザー watayuwatayu
提出日時 2023-07-19 16:39:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 30 ms / 5,000 ms
コード長 371 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 11,828 KB
実行使用メモリ 10,156 KB
最終ジャッジ日時 2023-10-19 19:12:04
合計ジャッジ時間 1,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
10,064 KB
testcase_01 AC 28 ms
10,064 KB
testcase_02 AC 28 ms
10,064 KB
testcase_03 AC 29 ms
10,156 KB
testcase_04 AC 29 ms
10,104 KB
testcase_05 AC 29 ms
10,100 KB
testcase_06 AC 29 ms
10,136 KB
testcase_07 AC 28 ms
10,148 KB
testcase_08 AC 29 ms
10,124 KB
testcase_09 AC 29 ms
10,120 KB
testcase_10 AC 29 ms
10,144 KB
testcase_11 AC 29 ms
10,096 KB
testcase_12 AC 29 ms
10,128 KB
testcase_13 AC 29 ms
10,148 KB
testcase_14 AC 28 ms
10,076 KB
testcase_15 AC 29 ms
10,148 KB
testcase_16 AC 29 ms
10,148 KB
testcase_17 AC 28 ms
10,064 KB
testcase_18 AC 30 ms
10,064 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N, K = map(int, input().split())
S = list(input())
stuck = []
if S[K - 1] == "(":
    start = K
    finish = N
    INC = 1
else:
    start = K - 2
    finish = -1
    INC = -1
stuck.append(S[K - 1])
for i in range(start, finish, INC):
    if stuck[-1] != S[i]:
        stuck.pop()
    else:
        stuck.append(S[i])
    if not stuck:
        print(i + 1)
        break
0