結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
沙耶花
|
| 提出日時 | 2021-04-16 20:35:57 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 422 ms / 3,000 ms |
| コード長 | 1,288 bytes |
| コンパイル時間 | 4,878 ms |
| コンパイル使用メモリ | 262,148 KB |
| 最終ジャッジ日時 | 2025-01-20 18:54:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#include <stdio.h>
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using mint = modint998244353;
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001
int main(){
int H,W;
cin>>H>>W;
vector<vector<int>> A(H,vector<int>(W));
vector<vector<pair<int,int>>> N(500001);
rep(i,H){
rep(j,W){
cin>>A[i][j];
N[A[i][j]].emplace_back(i,j);
}
}
int ans = 0;
vector<int> h(H,-1);
vector<int> w(W,-1);
rep(i,N.size()){
if(i==0)continue;
vector<int> y,x;
rep(j,N[i].size()){
int yy = N[i][j].first,xx = N[i][j].second;
if(h[yy]==-1){
h[yy] = y.size();
y.push_back(yy);
}
if(w[xx]==-1){
w[xx] = x.size();
x.push_back(xx);
}
}
sort(y.begin(),y.end());
sort(x.begin(),x.end());
mf_graph<int> G(y.size()+x.size()+2);
int S = y.size()+x.size();
int T = S+1;
rep(j,N[i].size()){
int yy = N[i][j].first,xx = N[i][j].second;
G.add_edge(h[yy],y.size() + w[xx],1);
}
rep(j,y.size()){
G.add_edge(S,j,1);
}
rep(j,x.size()){
G.add_edge(y.size()+j,T,1);
}
ans += G.flow(S,T);
rep(j,N[i].size()){
int yy = N[i][j].first,xx = N[i][j].second;
h[yy] = -1;
w[xx] = -1;
}
}
cout<<ans<<endl;
return 0;
}
沙耶花