結果

問題 No.22 括弧の対応
ユーザー m4tsum4tsu
提出日時 2018-06-13 12:27:24
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 14 ms / 5,000 ms
コード長 620 bytes
コンパイル時間 150 ms
コンパイル使用メモリ 10,556 KB
実行使用メモリ 8,224 KB
最終ジャッジ日時 2023-09-27 13:27:18
合計ジャッジ時間 1,434 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 13 ms
7,784 KB
testcase_01 AC 13 ms
7,784 KB
testcase_02 AC 13 ms
7,808 KB
testcase_03 AC 13 ms
8,216 KB
testcase_04 AC 13 ms
7,832 KB
testcase_05 AC 14 ms
7,760 KB
testcase_06 AC 14 ms
8,196 KB
testcase_07 AC 14 ms
8,212 KB
testcase_08 AC 13 ms
7,876 KB
testcase_09 AC 13 ms
7,756 KB
testcase_10 AC 14 ms
8,140 KB
testcase_11 AC 13 ms
7,832 KB
testcase_12 AC 12 ms
7,844 KB
testcase_13 AC 13 ms
8,192 KB
testcase_14 AC 13 ms
7,856 KB
testcase_15 AC 13 ms
8,224 KB
testcase_16 AC 14 ms
8,184 KB
testcase_17 AC 14 ms
7,796 KB
testcase_18 AC 14 ms
7,804 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n,k = map(int, input().split())
s = list(input())
#print(s)

count = 1 #k番目の文字を+1として同じ文字なら+1,違う文字なら-1する
if s[k-1] == "(":
    i = k
    while i <= n:
        if s[i] == "(":
            count += 1
        else:
            count -= 1
        
        if count == 0:
            print(i + 1)
            break
        else:
            i += 1

else:
    i = k - 2
    while i >= 0:
        if s[i] == ")":
            count += 1
        else:
            count -= 1
        
        if count == 0:
            print(i + 1)
            break
        else:
            i -= 1
0