結果

問題 No.684 Prefix Parenthesis
ユーザー prd_xxx
提出日時 2018-05-12 00:04:18
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
WA  
実行時間 -
コード長 360 bytes
コンパイル時間 148 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 11,136 KB
最終ジャッジ日時 2024-06-28 09:08:15
合計ジャッジ時間 2,991 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

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

pair_sum = op_sum = cl_sum = 0
pair = op = cl = 0
for c in S:
    if c == '(':
        op += 1
    else:
        if op > 0:
            op -= 1
            pair += 1
        else:
            cl += 1
    op_sum += op
    cl_sum += cl
    pair_sum += pair

if S[0] == ')':
    cl_sum -= 1
print(pair_sum*2 + min(op_sum, cl_sum)*2)
0