結果
| 問題 | No.1479 Matrix Eraser |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-06-09 09:32:26 |
| 言語 | C++23 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 389 ms / 3,000 ms |
| コード長 | 1,364 bytes |
| 記録 | |
| コンパイル時間 | 2,319 ms |
| コンパイル使用メモリ | 205,460 KB |
| 実行使用メモリ | 55,240 KB |
| 最終ジャッジ日時 | 2026-06-09 09:32:40 |
| 合計ジャッジ時間 | 11,263 ms |
|
ジャッジサーバーID (参考情報) |
judge1_1 / judge2_1 |
| 純コード判定待ち |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 39 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/maxflow>
int main() {
int H, W;
std::cin >> H >> W;
std::vector A(H, std::vector<int>(W));
for (auto &r : A) for (int &a : r) std::cin >> a;
std::vector<std::pair<int, int>> rows, cols;
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
if (A[i][j] == 0) continue;
rows.emplace_back(i, A[i][j]);
cols.emplace_back(j, A[i][j]);
}
}
std::sort(rows.begin(), rows.end());
rows.erase(std::unique(rows.begin(), rows.end()), rows.end());
std::sort(cols.begin(), cols.end());
cols.erase(std::unique(cols.begin(), cols.end()), cols.end());
int R = rows.size(), C = cols.size();
atcoder::mf_graph<int> graph(R + C + 2);
int source = R + C, sink = source + 1;
for (int i = 0; i < R; i++) graph.add_edge(source, i, 1);
for (int i = 0; i < C; i++) graph.add_edge(i + R, sink, 1);
for (int i = 0; i < H; i++) {
for (int j = 0; j < W; j++) {
int r = std::lower_bound(rows.begin(), rows.end(), std::pair{i, A[i][j]}) - rows.begin();
int c = std::lower_bound(cols.begin(), cols.end(), std::pair{j, A[i][j]}) - cols.begin();
graph.add_edge(r, c + R, 1);
}
}
std::cout << graph.flow(source, sink) << std::endl;
}