結果
問題 | No.22 括弧の対応 |
ユーザー | coder_So_hey |
提出日時 | 2022-12-31 16:54:11 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 19 ms / 5,000 ms |
コード長 | 641 bytes |
コンパイル時間 | 103 ms |
コンパイル使用メモリ | 10,808 KB |
実行使用メモリ | 8,404 KB |
最終ジャッジ日時 | 2023-08-17 16:48:30 |
合計ジャッジ時間 | 1,551 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge13 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 16 ms
7,828 KB |
testcase_01 | AC | 15 ms
7,888 KB |
testcase_02 | AC | 15 ms
7,808 KB |
testcase_03 | AC | 18 ms
8,232 KB |
testcase_04 | AC | 17 ms
8,240 KB |
testcase_05 | AC | 16 ms
7,848 KB |
testcase_06 | AC | 17 ms
8,224 KB |
testcase_07 | AC | 18 ms
8,156 KB |
testcase_08 | AC | 17 ms
8,252 KB |
testcase_09 | AC | 17 ms
8,228 KB |
testcase_10 | AC | 18 ms
8,228 KB |
testcase_11 | AC | 17 ms
7,852 KB |
testcase_12 | AC | 17 ms
8,168 KB |
testcase_13 | AC | 18 ms
8,404 KB |
testcase_14 | AC | 15 ms
7,840 KB |
testcase_15 | AC | 17 ms
8,280 KB |
testcase_16 | AC | 19 ms
8,388 KB |
testcase_17 | AC | 16 ms
7,992 KB |
testcase_18 | AC | 15 ms
7,964 KB |
ソースコード
N, K = map(int, input().split()) S = input() count = [1] * N index = 0 if S[K - 1] == '(': for i in range(1, N): if S[i] == '(': count[i] = count[i - 1] + 1 else: count[i] = count[i - 1] - 1 for j in range(K, N): if count[j] == count[K - 1] - 1: index = j + 1 break else: for i in range(N - 2, -1, -1): if S[i] == ')': count[i] = count[i + 1] + 1 else: count[i] = count[i + 1] - 1 for j in range(K - 2, -1, -1): if count[j] == count[K - 1] - 1: index = j + 1 break print(index)