結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,792 KB
testcase_01 AC 16 ms
7,712 KB
testcase_02 AC 16 ms
7,828 KB
testcase_03 AC 28 ms
7,824 KB
testcase_04 AC 45 ms
8,300 KB
testcase_05 AC 48 ms
8,284 KB
testcase_06 AC 27 ms
7,896 KB
testcase_07 AC 46 ms
8,280 KB
testcase_08 AC 19 ms
7,820 KB
testcase_09 WA -
testcase_10 AC 58 ms
8,212 KB
testcase_11 WA -
testcase_12 AC 21 ms
7,820 KB
testcase_13 AC 59 ms
8,212 KB
testcase_14 AC 57 ms
8,152 KB
testcase_15 AC 30 ms
7,828 KB
testcase_16 AC 52 ms
8,304 KB
testcase_17 AC 36 ms
8,216 KB
testcase_18 AC 16 ms
7,816 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 59 ms
8,184 KB
testcase_22 AC 49 ms
8,304 KB
testcase_23 AC 54 ms
8,308 KB
testcase_24 AC 57 ms
8,304 KB
testcase_25 AC 61 ms
8,264 KB
testcase_26 AC 16 ms
7,788 KB
testcase_27 AC 16 ms
7,796 KB
testcase_28 AC 15 ms
7,820 KB
testcase_29 WA -
testcase_30 AC 58 ms
8,156 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

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