結果

問題 No.1479 Matrix Eraser
ユーザー Today03Today03
提出日時 2024-05-23 15:02:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,086 bytes
コンパイル時間 2,373 ms
コンパイル使用メモリ 217,376 KB
実行使用メモリ 21,940 KB
最終ジャッジ日時 2024-05-23 15:02:13
合計ジャッジ時間 11,047 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
21,940 KB
testcase_01 AC 6 ms
14,980 KB
testcase_02 AC 5 ms
14,920 KB
testcase_03 AC 6 ms
14,980 KB
testcase_04 AC 5 ms
15,008 KB
testcase_05 AC 7 ms
14,920 KB
testcase_06 AC 6 ms
15,080 KB
testcase_07 AC 1,162 ms
15,996 KB
testcase_08 AC 2,054 ms
16,900 KB
testcase_09 TLE -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0