結果
| 問題 | No.684 Prefix Parenthesis |
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2021-01-16 09:28:00 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 556 bytes |
| 記録 | |
| コンパイル時間 | 1,172 ms |
| コンパイル使用メモリ | 85,036 KB |
| 実行使用メモリ | 94,756 KB |
| 最終ジャッジ日時 | 2026-05-21 15:31:51 |
| 合計ジャッジ時間 | 3,661 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 WA * 8 |
ソースコード
N = int(input())
S = input()
R = 0 # (((
LR = [] # ))((
L = 0 # ))
ans = 0
add = 0
cntL = 0
cntR = 0
for s in S:
if s == ")":
if cntR:
cntR -= 1
add += 2
else:
cntL += 1
elif s == "(":
cntR += 1
ans += add
if cntL and cntR:
LR.append((cntL, cntR))
elif cntL:
L += cntL
elif cntR:
R += cntR
LR.sort(key=lambda x: (x[0], -x[1]))
for l, r in LR:
d = min(R, l)
ans += 2 * d
R -= d
R += r
d = min(R, L)
ans += 2 * d
print(ans)
tktk_snsn