結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
PCTprobability
|
| 提出日時 | 2021-03-05 20:55:56 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 383 ms / 3,000 ms |
| コード長 | 2,005 bytes |
| コンパイル時間 | 4,499 ms |
| コンパイル使用メモリ | 269,092 KB |
| 最終ジャッジ日時 | 2025-01-19 10:27:16 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using ll = long long;
using ld = long double;
#define all(s) (s).begin(),(s).end()
#define vcin(n) for(ll i=0;i<ll(n.size());i++) cin>>n[i]
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)
#define rever(vec) reverse(vec.begin(), vec.end())
#define sor(vec) sort(vec.begin(), vec.end())
#define fi first
#define se second
#define P pair<ll,ll>
const ll mod = 998244353;
//const ll mod = 1000000007;
const ll inf = 2000000000000000000ll;
static const long double pi = 3.141592653589793;
void YesNo(bool a){if(a){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}}
void YESNO(bool a){if(a){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}}
template<class T,class U> void chmax(T& t,const U& u){if(t<u) t=u;}
template<class T,class U> void chmin(T& t,const U& u){if(t>u) t=u;}
ll modPow(ll a, ll n, ll mod) { ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; }
int main() {
/* mod は 1e9+7 */
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
cout<< fixed << setprecision(10);
ll a,b;
cin>>a>>b;
unordered_map<ll,vector<pair<ll,ll>>> m;
for(int i=0;i<a;i++){
for(int j=0;j<b;j++){
ll t;
cin>>t;
if(t){
m[t].emplace_back(i,j);
}
}
}
ll ans=0;
for(auto &x:m){
unordered_map<ll,ll> p,q;
ll u=1,v=1;
for(auto &y:x.se){
if(p[y.fi]==0){
p[y.fi]=u;
u++;
}
if(q[y.se]==0){
q[y.se]=v;
v++;
}
}
mf_graph<ll> g(u+v+2);
for(int j=0;j<u;j++){
g.add_edge(u+v,j,1);
}
for(int j=0;j<v;j++){
g.add_edge(u+j,u+v+1,1);
}
for(auto &h:x.se){
g.add_edge(p[h.fi]-1,u+q[h.se]-1,1);
}
ans+=g.flow(u+v,u+v+1);
}
cout<<ans<<endl;
}
PCTprobability