結果

問題 No.1479 Matrix Eraser
ユーザー 沙耶花沙耶花
提出日時 2021-04-16 20:35:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 355 ms / 3,000 ms
コード長 1,288 bytes
コンパイル時間 4,600 ms
コンパイル使用メモリ 272,532 KB
実行使用メモリ 23,640 KB
最終ジャッジ日時 2023-09-15 21:31:32
合計ジャッジ時間 14,131 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 65 ms
14,888 KB
testcase_01 AC 64 ms
14,616 KB
testcase_02 AC 65 ms
14,972 KB
testcase_03 AC 65 ms
14,956 KB
testcase_04 AC 65 ms
14,904 KB
testcase_05 AC 64 ms
14,728 KB
testcase_06 AC 64 ms
14,920 KB
testcase_07 AC 99 ms
15,764 KB
testcase_08 AC 123 ms
16,584 KB
testcase_09 AC 188 ms
18,420 KB
testcase_10 AC 298 ms
20,996 KB
testcase_11 AC 212 ms
18,912 KB
testcase_12 AC 108 ms
16,080 KB
testcase_13 AC 123 ms
16,488 KB
testcase_14 AC 110 ms
16,248 KB
testcase_15 AC 73 ms
15,100 KB
testcase_16 AC 115 ms
16,272 KB
testcase_17 AC 355 ms
22,080 KB
testcase_18 AC 349 ms
22,020 KB
testcase_19 AC 351 ms
22,032 KB
testcase_20 AC 351 ms
22,088 KB
testcase_21 AC 347 ms
22,288 KB
testcase_22 AC 352 ms
22,128 KB
testcase_23 AC 350 ms
22,012 KB
testcase_24 AC 346 ms
21,968 KB
testcase_25 AC 354 ms
22,116 KB
testcase_26 AC 350 ms
22,116 KB
testcase_27 AC 180 ms
18,792 KB
testcase_28 AC 180 ms
18,948 KB
testcase_29 AC 181 ms
19,092 KB
testcase_30 AC 181 ms
19,048 KB
testcase_31 AC 182 ms
19,392 KB
testcase_32 AC 121 ms
23,140 KB
testcase_33 AC 122 ms
23,440 KB
testcase_34 AC 122 ms
23,424 KB
testcase_35 AC 120 ms
23,072 KB
testcase_36 AC 120 ms
23,376 KB
testcase_37 AC 102 ms
17,888 KB
testcase_38 AC 204 ms
17,908 KB
testcase_39 AC 322 ms
23,640 KB
testcase_40 AC 65 ms
14,772 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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