結果

問題 No.1479 Matrix Eraser
ユーザー ruthenruthen
提出日時 2023-03-01 21:08:38
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 460 ms / 3,000 ms
コード長 1,075 bytes
コンパイル時間 2,849 ms
コンパイル使用メモリ 220,212 KB
実行使用メモリ 76,548 KB
最終ジャッジ日時 2023-10-15 00:43:48
合計ジャッジ時間 13,894 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 1 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 1 ms
4,368 KB
testcase_05 AC 1 ms
4,372 KB
testcase_06 AC 2 ms
4,372 KB
testcase_07 AC 39 ms
11,504 KB
testcase_08 AC 67 ms
17,512 KB
testcase_09 AC 157 ms
34,132 KB
testcase_10 AC 358 ms
63,404 KB
testcase_11 AC 190 ms
39,620 KB
testcase_12 AC 47 ms
13,892 KB
testcase_13 AC 66 ms
17,908 KB
testcase_14 AC 51 ms
14,444 KB
testcase_15 AC 10 ms
5,656 KB
testcase_16 AC 57 ms
15,828 KB
testcase_17 AC 449 ms
74,864 KB
testcase_18 AC 454 ms
74,764 KB
testcase_19 AC 452 ms
75,188 KB
testcase_20 AC 438 ms
74,648 KB
testcase_21 AC 440 ms
74,868 KB
testcase_22 AC 442 ms
75,308 KB
testcase_23 AC 453 ms
75,668 KB
testcase_24 AC 460 ms
75,208 KB
testcase_25 AC 447 ms
76,548 KB
testcase_26 AC 454 ms
75,212 KB
testcase_27 AC 294 ms
40,384 KB
testcase_28 AC 281 ms
40,996 KB
testcase_29 AC 298 ms
40,904 KB
testcase_30 AC 295 ms
40,564 KB
testcase_31 AC 300 ms
40,252 KB
testcase_32 AC 47 ms
30,536 KB
testcase_33 AC 46 ms
30,568 KB
testcase_34 AC 46 ms
30,580 KB
testcase_35 AC 48 ms
30,596 KB
testcase_36 AC 46 ms
30,548 KB
testcase_37 AC 23 ms
19,640 KB
testcase_38 AC 332 ms
75,152 KB
testcase_39 AC 270 ms
75,424 KB
testcase_40 AC 1 ms
4,368 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

#include <atcoder/maxflow>

#ifdef _RUTHEN
#include <debug.hpp>
#else
#define show(...) true
#endif

using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
template <class T> using V = vector<T>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int H, W;
    cin >> H >> W;
    V<V<int>> A(H, V<int>(W));
    rep(i, H) rep(j, W) cin >> A[i][j];
    map<int, int> mph[H], mpw[W];
    atcoder::mf_graph<int> G(H * W * 2 + 2);
    int s = H * W * 2, t = s + 1;
    rep(i, H) {
        rep(j, W) {
            if (A[i][j] == 0) continue;
            if (mph[i].count(A[i][j]) == 0) {
                mph[i][A[i][j]] = i * W + j;
                G.add_edge(s, i * W + j, 1);
            }
            if (mpw[j].count(A[i][j]) == 0) {
                mpw[j][A[i][j]] = i * W + j;
                G.add_edge(i * W + j + H * W, t, 1);
            }
            G.add_edge(mph[i][A[i][j]], mpw[j][A[i][j]] + H * W, 1);
        }
    }
    int ans = G.flow(s, t);
    cout << ans << '\n';
    return 0;
}
0