結果
問題 | No.1479 Matrix Eraser |
ユーザー | Today03 |
提出日時 | 2024-05-23 15:02:01 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,086 bytes |
コンパイル時間 | 2,695 ms |
コンパイル使用メモリ | 218,416 KB |
実行使用メモリ | 38,920 KB |
最終ジャッジ日時 | 2024-12-20 18:51:07 |
合計ジャッジ時間 | 73,907 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 25 TLE * 14 |
ソースコード
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 1e9 + 10; const ll INFL = 4e18; #include <atcoder/maxflow> using namespace atcoder; const int MX = 5e5 + 5; 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]; } } vector<vector<pair<int, int>>> P(MX); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { P[A[i][j]].push_back({i, j}); } } int ans = 0; for (int i = 1; i < MX; i++) { if (!P[i].empty()) { mf_graph<ll> mf(H + W + 2); for (auto [x, y] : P[i]) { mf.add_edge(x, H + y, 1); } for (int j = 0; j < H; j++) { mf.add_edge(H + W, j, 1); } for (int j = 0; j < W; j++) { mf.add_edge(H + j, H + W + 1, 1); } ans += mf.flow(H + W, H + W + 1); } } cout << ans << endl; }