結果
問題 | No.1479 Matrix Eraser |
ユーザー |
![]() |
提出日時 | 2021-03-05 20:58:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 428 ms / 3,000 ms |
コード長 | 875 bytes |
コンパイル時間 | 4,495 ms |
コンパイル使用メモリ | 265,748 KB |
最終ジャッジ日時 | 2025-01-19 10:27:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h>#include <atcoder/all>using namespace std;int h, w, a, i, j, res;unordered_map<int, vector<pair<int, int>>> mp;int main() {int h, w;cin >> h >> w;for(i = 0; i < h; i++) {for(j = 0; j < w; j++) {cin >> a;if(a) mp[a].emplace_back(i, j);}}for(auto &[key, vec] : mp) {unordered_map<int, int> ver, hor;int ver_idx = 0, hor_idx = 0;for(auto &[x, y] : vec) {if(!ver.count(x)) ver[x] = ver_idx++;if(!hor.count(y)) hor[y] = hor_idx++;}atcoder::mf_graph<int> mf(ver_idx + hor_idx + 2);const int s = ver_idx + hor_idx, t = ver_idx + hor_idx + 1;for(int i = 0; i < ver_idx; i++) mf.add_edge(s, i, 1);for(int i = ver_idx; i < ver_idx + hor_idx; i++) mf.add_edge(i, t, 1);for(auto &[x, y] : vec) mf.add_edge(ver[x], ver_idx + hor[y], 1);res += mf.flow(s, t);}cout << res << '\n';return 0;}