結果

問題 No.1479 Matrix Eraser
ユーザー 👑 PCTprobabilityPCTprobability
提出日時 2021-04-15 22:06:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 414 ms / 3,000 ms
コード長 2,075 bytes
コンパイル時間 4,682 ms
コンパイル使用メモリ 280,092 KB
実行使用メモリ 25,356 KB
最終ジャッジ日時 2023-09-15 00:09:42
合計ジャッジ時間 14,129 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 44 ms
5,836 KB
testcase_08 AC 78 ms
7,476 KB
testcase_09 AC 170 ms
12,256 KB
testcase_10 AC 321 ms
18,276 KB
testcase_11 AC 196 ms
13,480 KB
testcase_12 AC 54 ms
6,284 KB
testcase_13 AC 76 ms
7,400 KB
testcase_14 AC 61 ms
6,428 KB
testcase_15 AC 14 ms
4,380 KB
testcase_16 AC 71 ms
7,320 KB
testcase_17 AC 411 ms
22,316 KB
testcase_18 AC 409 ms
22,332 KB
testcase_19 AC 409 ms
22,196 KB
testcase_20 AC 414 ms
22,192 KB
testcase_21 AC 413 ms
22,188 KB
testcase_22 AC 411 ms
22,264 KB
testcase_23 AC 402 ms
22,236 KB
testcase_24 AC 399 ms
22,192 KB
testcase_25 AC 403 ms
22,284 KB
testcase_26 AC 411 ms
22,200 KB
testcase_27 AC 116 ms
8,900 KB
testcase_28 AC 116 ms
9,308 KB
testcase_29 AC 115 ms
9,164 KB
testcase_30 AC 115 ms
8,948 KB
testcase_31 AC 116 ms
9,308 KB
testcase_32 AC 54 ms
13,900 KB
testcase_33 AC 54 ms
14,008 KB
testcase_34 AC 54 ms
13,884 KB
testcase_35 AC 56 ms
14,144 KB
testcase_36 AC 56 ms
14,188 KB
testcase_37 AC 16 ms
4,380 KB
testcase_38 AC 165 ms
7,664 KB
testcase_39 AC 326 ms
25,356 KB
testcase_40 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
   assert(1<=a&&a<=500&&1<=b&&b<=500);
  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;
      assert(0<=t&&t<=500000);
      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;
}
0