結果
| 問題 |
No.1479 Matrix Eraser
|
| コンテスト | |
| ユーザー |
Today03
|
| 提出日時 | 2024-05-23 15:02:01 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,086 bytes |
| コンパイル時間 | 2,102 ms |
| コンパイル使用メモリ | 211,052 KB |
| 最終ジャッジ日時 | 2025-02-21 16:27:13 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 7 TLE * 1 -- * 31 |
ソースコード
#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;
}
Today03