結果

問題 No.684 Prefix Parenthesis
ユーザー prd_xxxprd_xxx
提出日時 2018-05-12 00:07:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 380 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 10,584 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2023-09-10 17:58:02
合計ジャッジ時間 2,577 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,848 KB
testcase_01 AC 15 ms
7,820 KB
testcase_02 AC 15 ms
7,820 KB
testcase_03 AC 26 ms
7,872 KB
testcase_04 AC 42 ms
8,284 KB
testcase_05 AC 44 ms
8,364 KB
testcase_06 AC 27 ms
7,832 KB
testcase_07 AC 45 ms
8,328 KB
testcase_08 AC 20 ms
7,752 KB
testcase_09 WA -
testcase_10 AC 57 ms
8,212 KB
testcase_11 WA -
testcase_12 AC 20 ms
7,832 KB
testcase_13 AC 57 ms
8,312 KB
testcase_14 AC 56 ms
8,264 KB
testcase_15 AC 29 ms
7,832 KB
testcase_16 AC 51 ms
8,384 KB
testcase_17 AC 34 ms
8,216 KB
testcase_18 AC 15 ms
7,956 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 AC 57 ms
8,260 KB
testcase_22 AC 53 ms
8,372 KB
testcase_23 AC 64 ms
8,328 KB
testcase_24 AC 55 ms
8,276 KB
testcase_25 AC 59 ms
8,372 KB
testcase_26 AC 15 ms
7,804 KB
testcase_27 AC 15 ms
7,784 KB
testcase_28 AC 14 ms
7,828 KB
testcase_29 WA -
testcase_30 AC 58 ms
8,284 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

for c in S:
    if c == '(': break
    cl_sum -= 1

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