結果

問題 No.684 Prefix Parenthesis
ユーザー prd_xxxprd_xxx
提出日時 2018-05-12 00:14:21
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 402 bytes
コンパイル時間 113 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 8,440 KB
最終ジャッジ日時 2023-09-10 18:02:54
合計ジャッジ時間 2,872 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,856 KB
testcase_01 AC 16 ms
7,760 KB
testcase_02 AC 16 ms
7,796 KB
testcase_03 WA -
testcase_04 AC 44 ms
8,224 KB
testcase_05 WA -
testcase_06 AC 27 ms
7,812 KB
testcase_07 AC 47 ms
8,300 KB
testcase_08 AC 19 ms
7,796 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 21 ms
7,848 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 30 ms
8,176 KB
testcase_16 AC 51 ms
8,268 KB
testcase_17 AC 35 ms
8,116 KB
testcase_18 AC 16 ms
7,800 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 59 ms
8,292 KB
testcase_22 AC 52 ms
8,224 KB
testcase_23 AC 66 ms
8,240 KB
testcase_24 AC 59 ms
8,220 KB
testcase_25 AC 61 ms
8,292 KB
testcase_26 AC 16 ms
7,900 KB
testcase_27 AC 16 ms
7,800 KB
testcase_28 AC 16 ms
7,848 KB
testcase_29 WA -
testcase_30 AC 62 ms
8,332 KB
権限があれば一括ダウンロードができます

ソースコード

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

pena = 0
for c in S:
    if c == '(': break
    pena += 1

print(pair_sum*2 + max(0, min(op_sum, cl_sum) - pena)*2)
0