結果
問題 | No.1324 Approximate the Matrix |
ユーザー | ああいい |
提出日時 | 2022-04-14 11:05:20 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,808 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,416 KB |
実行使用メモリ | 90,012 KB |
最終ジャッジ日時 | 2024-06-06 14:03:15 |
合計ジャッジ時間 | 12,433 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 39 ms
53,248 KB |
testcase_01 | AC | 39 ms
53,120 KB |
testcase_02 | AC | 38 ms
52,736 KB |
testcase_03 | AC | 474 ms
83,176 KB |
testcase_04 | AC | 490 ms
83,984 KB |
testcase_05 | AC | 485 ms
84,108 KB |
testcase_06 | AC | 485 ms
83,440 KB |
testcase_07 | AC | 519 ms
83,252 KB |
testcase_08 | AC | 118 ms
77,824 KB |
testcase_09 | AC | 133 ms
78,048 KB |
testcase_10 | AC | 151 ms
78,592 KB |
testcase_11 | AC | 189 ms
79,456 KB |
testcase_12 | AC | 142 ms
78,520 KB |
testcase_13 | AC | 115 ms
77,724 KB |
testcase_14 | AC | 185 ms
79,616 KB |
testcase_15 | AC | 137 ms
78,440 KB |
testcase_16 | WA | - |
testcase_17 | AC | 189 ms
79,472 KB |
testcase_18 | AC | 129 ms
78,112 KB |
testcase_19 | WA | - |
testcase_20 | AC | 116 ms
77,176 KB |
testcase_21 | AC | 117 ms
76,880 KB |
testcase_22 | AC | 58 ms
68,224 KB |
testcase_23 | AC | 186 ms
79,076 KB |
testcase_24 | AC | 241 ms
80,548 KB |
testcase_25 | AC | 219 ms
79,564 KB |
testcase_26 | AC | 180 ms
79,700 KB |
testcase_27 | AC | 154 ms
78,540 KB |
testcase_28 | AC | 38 ms
53,248 KB |
testcase_29 | AC | 48 ms
60,928 KB |
testcase_30 | AC | 47 ms
60,928 KB |
testcase_31 | AC | 58 ms
65,280 KB |
testcase_32 | AC | 37 ms
53,248 KB |
testcase_33 | AC | 38 ms
53,268 KB |
testcase_34 | AC | 37 ms
53,632 KB |
testcase_35 | AC | 37 ms
53,760 KB |
testcase_36 | AC | 40 ms
53,120 KB |
testcase_37 | AC | 886 ms
90,012 KB |
testcase_38 | AC | 890 ms
89,528 KB |
testcase_39 | AC | 1,335 ms
89,920 KB |
testcase_40 | AC | 989 ms
89,716 KB |
testcase_41 | AC | 896 ms
89,984 KB |
testcase_42 | AC | 56 ms
69,504 KB |
testcase_43 | AC | 56 ms
69,760 KB |
testcase_44 | AC | 56 ms
70,144 KB |
ソースコード
#その2 最初はコストが全部正の場合に使えるダイクストラ from heapq import heappush,heappop class MinCostFlow: inf = 10 ** 10 def __init__(self,N): self.N = N self.G = [[] for _ in range(N)] self.H = [0] * N self.edge = [] def add_edge(self,fr,to,cap,cost): e = [to,cap,cost,None] r = e[3] = [fr,0,-cost,e] self.G[fr].append(e) self.G[to].append(r) self.edge.append(e) def get_edge(self,i): return self.edge[i] def flow(self,s,t,f): N = self.N G = self.G inf = MinCostFlow.inf res = 0 H = self.H #ポテンシャル、コストが最初は正なので、最初は0でいい prev_v = [0] * N prev_e = [None] * N d0 = [inf] * N dist = [inf] * N while f: dist[:] = d0 dist[s] = 0 vis = [False] * N q = [(0,s)] while q: c,v = heappop(q) if vis[v]:continue vis[v] = True if v == t:break #r0 = dist[v] + H[v] for e in G[v]: w,cap,cost,_ = e cost = cost - H[w] + H[v] if cap > 0 and dist[v] + cost < dist[w]: dist[w] = dist[v] + cost prev_v[w] = v prev_e[w] = e heappush(q,(dist[w],w)) if dist[t] == inf: return None """ for i in range(N): H[i] += dist[i] """ for i in range(N): if vis[v]: H[i] += dist[i] - dist[t] d = f v = t while v != s: d = min(d,prev_e[v][1]) v = prev_v[v] f -= d res += d * -H[s] v = t while v != s: e = prev_e[v] e[1] -= d e[3][1] += d v = prev_v[v] return res import sys rr = sys.stdin N,K = map(int,rr.readline().split()) A = list(map(int,rr.readline().split())) B = list(map(int,rr.readline().split())) P = [list(map(int,rr.readline().split())) for _ in range(N)] mincost = MinCostFlow(N + N + 2) s = N + N t = N + N + 1 inf = 400 for i in range(N): for j in range(N): v = N + j for k in range(1,min(A[i],B[j])+1): mincost.add_edge(i,v,1,inf + (2 * (k - 1) + 1 - 2 * P[i][j])) for i in range(N): mincost.add_edge(s,i,A[i],0) for j in range(N): mincost.add_edge(j + N,t,B[j],0) ans = 0 for i in range(N): for j in range(N): ans += P[i][j] ** 2 ans += mincost.flow(s,t,K) - inf * K print(ans)