結果

問題 No.1479 Matrix Eraser
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-09-04 06:49:03
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 337 ms / 3,000 ms
コード長 1,037 bytes
コンパイル時間 6,309 ms
コンパイル使用メモリ 321,788 KB
実行使用メモリ 23,480 KB
最終ジャッジ日時 2023-09-04 06:49:20
合計ジャッジ時間 16,183 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
15,024 KB
testcase_01 AC 8 ms
15,032 KB
testcase_02 AC 8 ms
14,852 KB
testcase_03 AC 9 ms
14,880 KB
testcase_04 AC 9 ms
14,836 KB
testcase_05 AC 8 ms
14,836 KB
testcase_06 AC 9 ms
14,932 KB
testcase_07 AC 48 ms
15,740 KB
testcase_08 AC 76 ms
16,284 KB
testcase_09 AC 153 ms
17,808 KB
testcase_10 AC 278 ms
20,224 KB
testcase_11 AC 177 ms
18,324 KB
testcase_12 AC 56 ms
15,904 KB
testcase_13 AC 76 ms
16,340 KB
testcase_14 AC 60 ms
15,904 KB
testcase_15 AC 19 ms
14,960 KB
testcase_16 AC 68 ms
16,288 KB
testcase_17 AC 330 ms
21,020 KB
testcase_18 AC 329 ms
20,908 KB
testcase_19 AC 329 ms
21,096 KB
testcase_20 AC 330 ms
21,040 KB
testcase_21 AC 330 ms
21,168 KB
testcase_22 AC 330 ms
20,960 KB
testcase_23 AC 337 ms
21,004 KB
testcase_24 AC 331 ms
21,024 KB
testcase_25 AC 333 ms
20,920 KB
testcase_26 AC 333 ms
21,020 KB
testcase_27 AC 133 ms
18,044 KB
testcase_28 AC 131 ms
17,808 KB
testcase_29 AC 132 ms
18,128 KB
testcase_30 AC 132 ms
18,028 KB
testcase_31 AC 134 ms
18,252 KB
testcase_32 AC 71 ms
23,404 KB
testcase_33 AC 72 ms
23,424 KB
testcase_34 AC 73 ms
23,424 KB
testcase_35 AC 73 ms
23,260 KB
testcase_36 AC 73 ms
23,480 KB
testcase_37 AC 41 ms
14,896 KB
testcase_38 AC 171 ms
17,172 KB
testcase_39 AC 312 ms
22,824 KB
testcase_40 AC 8 ms
14,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
    
0