結果

問題 No.1479 Matrix Eraser
ユーザー SSRS
提出日時 2021-04-16 20:21:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 578 ms / 3,000 ms
コード長 1,474 bytes
コンパイル時間 2,403 ms
コンパイル使用メモリ 193,880 KB
実行使用メモリ 31,872 KB
最終ジャッジ日時 2024-07-02 22:28:59
合計ジャッジ時間 13,079 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
#include <atcoder/maxflow>
using namespace std;
using namespace atcoder;
int main(){
int H, W;
cin >> H >> W;
vector<vector<int>> A(H, vector<int>(W));
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
cin >> A[i][j];
}
}
map<int, vector<pair<int, int>>> mp;
for (int i = 0; i < H; i++){
for (int j = 0; j < W; j++){
if (A[i][j] > 0){
mp[A[i][j]].push_back(make_pair(i, j));
}
}
}
int ans = 0;
for (auto P : mp){
int cnt = P.second.size();
vector<int> X, Y;
for (int i = 0; i < cnt; i++){
X.push_back(P.second[i].first);
Y.push_back(P.second[i].second);
}
sort(X.begin(), X.end());
X.erase(unique(X.begin(), X.end()), X.end());
sort(Y.begin(), Y.end());
Y.erase(unique(Y.begin(), Y.end()), Y.end());
int Xcnt = X.size(), Ycnt = Y.size();
vector<int> x(cnt), y(cnt);
for (int i = 0; i < cnt; i++){
x[i] = lower_bound(X.begin(), X.end(), P.second[i].first) - X.begin();
y[i] = lower_bound(Y.begin(), Y.end(), P.second[i].second) - Y.begin();
}
mf_graph<int> G(Xcnt + Ycnt + 2);
for (int i = 0; i < Xcnt; i++){
G.add_edge(Xcnt + Ycnt, i, 1);
}
for (int i = 0; i < Ycnt; i++){
G.add_edge(Xcnt + i, Xcnt + Ycnt + 1, 1);
}
for (int i = 0; i < cnt; i++){
G.add_edge(x[i], Xcnt + y[i], 1);
}
ans += G.flow(Xcnt + Ycnt, Xcnt + Ycnt + 1);
}
cout << ans << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0