結果

問題 No.684 Prefix Parenthesis
ユーザー tktk_snsntktk_snsn
提出日時 2021-01-16 10:28:57
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 368 bytes
コンパイル時間 285 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 89,600 KB
最終ジャッジ日時 2024-05-05 12:49:12
合計ジャッジ時間 4,396 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 36 ms
51,968 KB
testcase_02 AC 35 ms
52,096 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 121 ms
88,192 KB
testcase_14 AC 129 ms
88,192 KB
testcase_15 AC 78 ms
79,872 KB
testcase_16 AC 120 ms
87,808 KB
testcase_17 AC 91 ms
82,304 KB
testcase_18 AC 46 ms
60,544 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 88 ms
89,216 KB
testcase_23 AC 91 ms
89,600 KB
testcase_24 AC 132 ms
89,216 KB
testcase_25 WA -
testcase_26 AC 35 ms
51,712 KB
testcase_27 AC 35 ms
51,712 KB
testcase_28 AC 35 ms
52,096 KB
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
S = input()

s_sum = 0
s_min = 0
P = []
for s in S:
    if s == "(":
        s_sum += 1
    else:
        s_sum -= 1
    s_min = min(s_min, s_sum)
    P.append((s_sum, s_min))

P.sort(key=lambda x: (-x[1], x[0]))
t_min = 0
t_sum = 0
for s, m in P:
    t_min = min(t_min, t_sum + m)
    t_sum += s

ans = N * (N + 1) // 2 - t_sum + 2 * t_min
print(ans)
0