結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
たたき@競プロ
|
| 提出日時 | 2023-09-04 06:49:03 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 298 ms / 3,000 ms |
| コード長 | 1,037 bytes |
| コンパイル時間 | 6,351 ms |
| コンパイル使用メモリ | 324,712 KB |
| 実行使用メモリ | 23,636 KB |
| 最終ジャッジ日時 | 2024-06-22 06:11:05 |
| 合計ジャッジ時間 | 13,344 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint=modint998244353; //1000000007;
using ll=long long;
using pp=pair<int,int>;
#define sr string
#define vc vector
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
int h,w;cin>>h>>w;
vc v(5e5+1,vc<pp>(0));
rep(i,h)rep(j,w){
int a;cin>>a;
if(a)v[a].pb({i,j});
}
int ans=0;
for(auto vx:v){
if(!vx.size())continue;
int n=vx.size();
unordered_map<int,int>hm,wm;
int ch=0,cw=0;
for(auto [a,b]:vx)hm[a]=0,wm[b]=0;
for(auto& [a,b]:hm)b=ch++;
for(auto&[a,b]:wm)b=cw++;
mf_graph<int>g(ch+cw+2);
int sv=ch+cw; int gv=sv+1;
for(auto [a,b]:vx)g.add_edge(hm[a],ch+wm[b],2);
rep(i,ch)g.add_edge(sv,i,1);
rep(i,cw)g.add_edge(ch+i,gv,1);
int res=g.flow(sv,gv);
ans+=res;
//cout<<res<<' ';
}
cout<<ans;
}
たたき@競プロ