結果
問題 |
No.1479 Matrix Eraser
|
ユーザー |
|
提出日時 | 2023-03-01 21:08:38 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 684 ms / 3,000 ms |
コード長 | 1,075 bytes |
コンパイル時間 | 2,740 ms |
コンパイル使用メモリ | 214,444 KB |
最終ジャッジ日時 | 2025-02-11 00:36:01 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 39 |
ソースコード
#include <bits/stdc++.h> using namespace std; #include <atcoder/maxflow> #ifdef _RUTHEN #include <debug.hpp> #else #define show(...) true #endif using ll = long long; #define rep(i, n) for (int i = 0; i < (n); i++) template <class T> using V = vector<T>; int main() { ios::sync_with_stdio(false); cin.tie(0); int H, W; cin >> H >> W; V<V<int>> A(H, V<int>(W)); rep(i, H) rep(j, W) cin >> A[i][j]; map<int, int> mph[H], mpw[W]; atcoder::mf_graph<int> G(H * W * 2 + 2); int s = H * W * 2, t = s + 1; rep(i, H) { rep(j, W) { if (A[i][j] == 0) continue; if (mph[i].count(A[i][j]) == 0) { mph[i][A[i][j]] = i * W + j; G.add_edge(s, i * W + j, 1); } if (mpw[j].count(A[i][j]) == 0) { mpw[j][A[i][j]] = i * W + j; G.add_edge(i * W + j + H * W, t, 1); } G.add_edge(mph[i][A[i][j]], mpw[j][A[i][j]] + H * W, 1); } } int ans = G.flow(s, t); cout << ans << '\n'; return 0; }