結果
| 問題 | No.1479 Matrix Eraser |
| コンテスト | |
| ユーザー |
ygd.
|
| 提出日時 | 2021-04-17 14:56:11 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 823 bytes |
| 記録 | |
| コンパイル時間 | 87 ms |
| コンパイル使用メモリ | 12,672 KB |
| 実行使用メモリ | 10,880 KB |
| 最終ジャッジ日時 | 2024-07-03 22:37:13 |
| 合計ジャッジ時間 | 3,190 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | RE * 2 |
| other | RE * 39 |
ソースコード
from collections import defaultdict
import networkx as nx
H,W = map(int,input().split())
A = []
dic = defaultdict(list)
for i in range(H):
a = list(map(int,input().split()))
for j in range(W):
num = a[j]
if num != 0:
dic[num].append((i,j))
A.append(a)
print(A)
print(dic)
key_list = list(dic.keys())
#頂点は0~H+W-1
S = H+W
T = H+W + 1
ans = 0
for num in key_list:
G1 = nx.Graph()
G1 = nx.DiGraph(G1)
SX = set([])
SY = set([])
for x,y in dic[num]:
SX.add(x)
SY.add(y)
G1.add_edge(x,y+H,capacity=1)
print(SX,SY)
for x in SX:
G1.add_edge(S,x,capacity=1)
for y in SY:
G1.add_edge(y+H,T,capacity=1)
flow_value, flows = nx.maximum_flow(G1,S,T)
#print(num,flow_value,flows)
ans += flow_value
print(ans)
ygd.