結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
pockyny
|
| 提出日時 | 2021-04-16 20:38:05 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 986 ms / 3,000 ms |
| コード長 | 1,024 bytes |
| コンパイル時間 | 1,234 ms |
| コンパイル使用メモリ | 103,280 KB |
| 最終ジャッジ日時 | 2025-01-20 18:57:08 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#include <iostream>
#include <vector>
#include <atcoder/maxflow>
#include <utility>
#include <map>
using namespace std;
using namespace atcoder;
int a[510][510];
map<int,int> mp1[510];
map<int,int> mp2[510];
int main(){
int i,j,h,w; cin >> h >> w;
int now = 0;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
cin >> a[i][j];
if(a[i][j]==0) continue;
if(mp1[i].find(a[i][j])==mp1[i].end()){
mp1[i][a[i][j]] = now; now++;
}
if(mp2[j].find(a[i][j])==mp2[j].end()){
mp2[j][a[i][j]] = now; now++;
}
}
}
mf_graph<int> g(now + 2);
int s = now,t = now + 1;
for(i=0;i<h;i++){
for(auto x:mp1[i]) g.add_edge(s,x.second,1);
}
for(j=0;j<w;j++){
for(auto x:mp2[j]) g.add_edge(x.second,t,1);
}
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(a[i][j]==0) continue;
g.add_edge(mp1[i][a[i][j]],mp2[j][a[i][j]],1);
}
}
cout << g.flow(s,t) << endl;
}
pockyny