結果
| 問題 |
No.22 括弧の対応
|
| コンテスト | |
| ユーザー |
nagitaosu
|
| 提出日時 | 2020-03-13 15:09:23 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 37 ms / 5,000 ms |
| コード長 | 532 bytes |
| コンパイル時間 | 147 ms |
| コンパイル使用メモリ | 12,544 KB |
| 実行使用メモリ | 11,264 KB |
| 最終ジャッジ日時 | 2024-07-20 07:48:19 |
| 合計ジャッジ時間 | 1,581 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 |
ソースコード
#!/usr/bin/env python3
import sys
input = sys.stdin.readline
n, k = map(int, input().split())
s = input().rstrip()
depth = [(0, 0)]
for ch in s:
if ch == "(":
depth.append((depth[-1][1], depth[-1][1] + 1))
else:
depth.append((depth[-1][1], depth[-1][1] - 1))
frm, too = depth[k]
if frm < too:
for i in range(k, n+1):
if depth[i] == (too, frm):
print(i)
exit()
else:
for i in range(k, -1, -1):
if depth[i] == (too, frm):
print(i)
exit()
nagitaosu