結果

問題 No.22 括弧の対応
ユーザー KudeKude
提出日時 2020-09-04 16:05:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 5,000 ms
コード長 336 bytes
コンパイル時間 1,740 ms
コンパイル使用メモリ 86,704 KB
実行使用メモリ 75,792 KB
最終ジャッジ日時 2023-09-27 13:50:19
合計ジャッジ時間 2,815 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
71,188 KB
testcase_01 AC 66 ms
71,280 KB
testcase_02 AC 63 ms
71,112 KB
testcase_03 AC 64 ms
71,180 KB
testcase_04 AC 65 ms
70,960 KB
testcase_05 AC 63 ms
71,032 KB
testcase_06 AC 65 ms
70,956 KB
testcase_07 AC 74 ms
75,524 KB
testcase_08 AC 64 ms
71,168 KB
testcase_09 AC 69 ms
75,792 KB
testcase_10 AC 65 ms
71,096 KB
testcase_11 AC 65 ms
71,096 KB
testcase_12 AC 69 ms
75,716 KB
testcase_13 AC 70 ms
75,780 KB
testcase_14 AC 67 ms
75,752 KB
testcase_15 AC 64 ms
71,320 KB
testcase_16 AC 63 ms
71,100 KB
testcase_17 AC 64 ms
70,912 KB
testcase_18 AC 66 ms
71,032 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, k = map(int, input().split())
k -= 1
s = input()
flipped = s[k] == ')'
if flipped:
    s = ''.join('()'[c == '('] for c in reversed(s))
    k = n - 1 - k
depth = 1
for i in range(k + 1, n):
    if s[i] == ')':
        depth -= 1
    else:
        depth += 1
    if depth == 0:
        break
if flipped:
    i = n - 1 - i
print(i + 1)
0