結果

問題 No.1479 Matrix Eraser
ユーザー MisterMister
提出日時 2021-04-16 21:27:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 734 ms / 3,000 ms
コード長 1,007 bytes
コンパイル時間 1,059 ms
コンパイル使用メモリ 101,804 KB
実行使用メモリ 22,572 KB
最終ジャッジ日時 2023-09-15 23:32:19
合計ジャッジ時間 12,837 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
14,840 KB
testcase_01 AC 7 ms
14,768 KB
testcase_02 AC 6 ms
14,584 KB
testcase_03 AC 7 ms
14,788 KB
testcase_04 AC 7 ms
14,840 KB
testcase_05 AC 7 ms
14,628 KB
testcase_06 AC 7 ms
14,820 KB
testcase_07 AC 62 ms
15,700 KB
testcase_08 AC 105 ms
16,108 KB
testcase_09 AC 240 ms
17,668 KB
testcase_10 AC 526 ms
20,124 KB
testcase_11 AC 294 ms
18,224 KB
testcase_12 AC 84 ms
15,908 KB
testcase_13 AC 101 ms
16,352 KB
testcase_14 AC 83 ms
15,900 KB
testcase_15 AC 20 ms
15,048 KB
testcase_16 AC 87 ms
16,104 KB
testcase_17 AC 650 ms
21,192 KB
testcase_18 AC 653 ms
21,184 KB
testcase_19 AC 652 ms
21,216 KB
testcase_20 AC 655 ms
21,192 KB
testcase_21 AC 658 ms
21,180 KB
testcase_22 AC 661 ms
21,248 KB
testcase_23 AC 650 ms
21,248 KB
testcase_24 AC 652 ms
21,116 KB
testcase_25 AC 661 ms
21,188 KB
testcase_26 AC 659 ms
21,140 KB
testcase_27 AC 123 ms
17,860 KB
testcase_28 AC 121 ms
18,000 KB
testcase_29 AC 123 ms
18,284 KB
testcase_30 AC 122 ms
18,184 KB
testcase_31 AC 123 ms
18,012 KB
testcase_32 AC 58 ms
22,388 KB
testcase_33 AC 57 ms
22,404 KB
testcase_34 AC 57 ms
22,320 KB
testcase_35 AC 57 ms
22,328 KB
testcase_36 AC 57 ms
22,572 KB
testcase_37 AC 20 ms
14,640 KB
testcase_38 AC 158 ms
16,892 KB
testcase_39 AC 734 ms
22,504 KB
testcase_40 AC 7 ms
14,836 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/maxflow>
#include <iostream>
#include <vector>
#include <set>

using namespace std;
constexpr int X = 500000;

void solve() {
    int h, w;
    cin >> h >> w;

    vector<vector<pair<int, int>>> ess(X);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int x;
            cin >> x;
            if (x > 0) ess[--x].emplace_back(i, j);
        }
    }

    int ans = 0;
    for (const auto& es : ess) {
        if (es.empty()) continue;

        atcoder::mf_graph<int> graph(h + w + 2);
        int s = h + w, g = s + 1;

        set<int> is, js;
        for (auto [i, j] : es) {
            is.insert(i);
            js.insert(j);
            graph.add_edge(i, h + j, 1);
        }

        for (auto i : is) graph.add_edge(s, i, 1);
        for (auto j : js) graph.add_edge(h + j, g, 1);
        ans += graph.flow(s, g);
    }

    cout << ans << "\n";
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    solve();

    return 0;
}
0