結果
問題 | No.1324 Approximate the Matrix |
ユーザー | ああいい |
提出日時 | 2022-04-14 10:48:36 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,704 bytes |
コンパイル時間 | 176 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 89,984 KB |
最終ジャッジ日時 | 2024-12-24 05:54:59 |
合計ジャッジ時間 | 12,337 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
52,736 KB |
testcase_01 | AC | 43 ms
52,992 KB |
testcase_02 | AC | 42 ms
52,736 KB |
testcase_03 | AC | 514 ms
83,288 KB |
testcase_04 | AC | 481 ms
83,388 KB |
testcase_05 | AC | 516 ms
84,180 KB |
testcase_06 | AC | 509 ms
83,092 KB |
testcase_07 | AC | 543 ms
83,732 KB |
testcase_08 | AC | 128 ms
77,824 KB |
testcase_09 | AC | 137 ms
78,020 KB |
testcase_10 | AC | 152 ms
78,720 KB |
testcase_11 | AC | 200 ms
79,488 KB |
testcase_12 | AC | 145 ms
78,324 KB |
testcase_13 | AC | 124 ms
76,744 KB |
testcase_14 | AC | 198 ms
79,744 KB |
testcase_15 | AC | 140 ms
78,304 KB |
testcase_16 | AC | 108 ms
76,316 KB |
testcase_17 | AC | 207 ms
79,360 KB |
testcase_18 | WA | - |
testcase_19 | AC | 148 ms
77,564 KB |
testcase_20 | AC | 133 ms
77,140 KB |
testcase_21 | AC | 130 ms
76,416 KB |
testcase_22 | AC | 65 ms
68,224 KB |
testcase_23 | AC | 200 ms
78,856 KB |
testcase_24 | AC | 258 ms
80,544 KB |
testcase_25 | AC | 225 ms
79,648 KB |
testcase_26 | AC | 198 ms
79,536 KB |
testcase_27 | AC | 167 ms
78,256 KB |
testcase_28 | AC | 41 ms
52,992 KB |
testcase_29 | AC | 49 ms
60,416 KB |
testcase_30 | AC | 51 ms
60,544 KB |
testcase_31 | AC | 61 ms
64,896 KB |
testcase_32 | AC | 40 ms
52,864 KB |
testcase_33 | AC | 41 ms
53,120 KB |
testcase_34 | AC | 43 ms
53,248 KB |
testcase_35 | AC | 43 ms
53,120 KB |
testcase_36 | AC | 49 ms
52,864 KB |
testcase_37 | AC | 885 ms
89,984 KB |
testcase_38 | AC | 898 ms
89,592 KB |
testcase_39 | AC | 940 ms
89,520 KB |
testcase_40 | AC | 848 ms
89,600 KB |
testcase_41 | AC | 838 ms
89,600 KB |
testcase_42 | AC | 61 ms
69,376 KB |
testcase_43 | AC | 60 ms
69,632 KB |
testcase_44 | AC | 60 ms
69,760 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 q = [(0,s)] while q: c,v = heappop(q) if dist[v] < c:continue if v == t:break r0 = dist[v] + H[v] for e in G[v]: w,cap,cost,_ = e if cap > 0 and r0 + cost - H[w] < dist[w]: dist[w] = r = r0 + cost - H[w] prev_v[w] = v prev_e[w] = e heappush(q,(r,w)) if dist[t] == inf: return None """ for i in range(N): H[i] += dist[i] """ for i in range(N): if dist[i] < inf: H[i] += dist[i] d = f v = t while v != s: d = min(d,prev_e[v][1]) v = prev_v[v] f -= d res += d * H[t] 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)