結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-11-20 13:02:50 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 33 ms / 5,000 ms |
| コード長 | 784 bytes |
| コンパイル時間 | 111 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-07-20 07:27:09 |
| 合計ジャッジ時間 | 1,421 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
def main():
N, K = map(int, input().split())
S = input()
if S[K-1] == ")":
next_index = (K-1)-1
count = 0
while count != 1:
if S[next_index] == "(":
count += 1
else:
count -= 1
next_index = next_index - 1
# カウンタがすでに進んでいるので1を足し、
# 0始まりから1始まりに直すために更に1を足す
print(next_index + 2)
else:
next_index = (K-1)+1
count = 0
while count != 1:
if S[next_index] == ")":
count += 1
else:
count -= 1
next_index = next_index + 1
print(next_index)
if __name__ == '__main__':
main()