結果

問題 No.22 括弧の対応
ユーザー TomoyarnTomoyarn
提出日時 2022-02-19 11:43:46
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 79 ms / 5,000 ms
コード長 482 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 87,236 KB
実行使用メモリ 76,024 KB
最終ジャッジ日時 2023-09-11 20:37:13
合計ジャッジ時間 3,262 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,284 KB
testcase_01 AC 71 ms
71,132 KB
testcase_02 AC 72 ms
71,156 KB
testcase_03 AC 79 ms
75,652 KB
testcase_04 AC 73 ms
75,932 KB
testcase_05 AC 74 ms
75,776 KB
testcase_06 AC 74 ms
76,024 KB
testcase_07 AC 74 ms
75,848 KB
testcase_08 AC 75 ms
75,984 KB
testcase_09 AC 73 ms
75,932 KB
testcase_10 AC 73 ms
75,764 KB
testcase_11 AC 78 ms
75,820 KB
testcase_12 AC 77 ms
75,896 KB
testcase_13 AC 74 ms
75,884 KB
testcase_14 AC 73 ms
75,880 KB
testcase_15 AC 73 ms
75,868 KB
testcase_16 AC 74 ms
75,780 KB
testcase_17 AC 71 ms
71,444 KB
testcase_18 AC 71 ms
71,320 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#yukicoder No.22 括弧の対応
N, K = map(int, input().split())
S = input()
d = []
cnt = 0
for i in range(N):
    if S[i] == "(":
        cnt += 1
    else:
        cnt -= 1
    d.append(cnt)

i = K - 1
if S[i] == ")":
    while True:
        i -= 1
        if d[i] == d[K - 1] + 1 and S[i] == "(":
            print(i + 1)
            break
else:
    while True:
        i += 1
        if d[i] == d[K - 1] - 1 and S[i] == ")":
            print(i + 1)
            break

        
0