結果

問題 No.2478 Disjoint-Sparse-Table Optimization
ユーザー maspymaspy
提出日時 2023-11-26 04:16:27
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 685 bytes
コンパイル時間 72 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 9,984 KB
最終ジャッジ日時 2023-11-26 04:16:29
合計ジャッジ時間 1,263 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import networkx as nx

N=int(input())
L = []
R = []
for _ in range(N):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    L.append(a)
    R.append(b)
A = [0] + list(map(int,input().split()))
for i in range(2*N-1):
    A[i+1] += A[i]

G = nx.Graph()
edges = []
for i in range(N):
    for j in range(N):
        if i == j:
            continue
        if L[i] < L[j] < R[i] < R[j]:
            edges.append((i, j, A[R[i]] - A[L[j]]))
G.add_weighted_edges_from(edges)

match = nx.max_weight_matching(G)
wt = 0
for a,b,c in edges:
    if (a,b) in match or (b,a) in match:
        wt += c

ANS = 0
for i in range(N):
    print(L[i],R[i])
    ANS += A[R[i]] - A[L[i]]
ANS -= wt

print(ANS)
0