結果

問題 No.1479 Matrix Eraser
ユーザー ruthenruthen
提出日時 2023-03-01 21:17:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 397 ms / 3,000 ms
コード長 1,085 bytes
コンパイル時間 2,644 ms
コンパイル使用メモリ 219,300 KB
実行使用メモリ 72,276 KB
最終ジャッジ日時 2023-10-15 00:51:00
合計ジャッジ時間 12,246 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,368 KB
testcase_01 AC 2 ms
4,368 KB
testcase_02 AC 2 ms
4,368 KB
testcase_03 AC 1 ms
4,368 KB
testcase_04 AC 2 ms
4,368 KB
testcase_05 AC 2 ms
4,372 KB
testcase_06 AC 2 ms
4,368 KB
testcase_07 AC 33 ms
11,120 KB
testcase_08 AC 64 ms
17,388 KB
testcase_09 AC 157 ms
34,108 KB
testcase_10 AC 311 ms
60,264 KB
testcase_11 AC 187 ms
38,800 KB
testcase_12 AC 43 ms
13,568 KB
testcase_13 AC 59 ms
17,072 KB
testcase_14 AC 45 ms
13,980 KB
testcase_15 AC 9 ms
5,700 KB
testcase_16 AC 51 ms
15,332 KB
testcase_17 AC 384 ms
71,460 KB
testcase_18 AC 381 ms
71,796 KB
testcase_19 AC 379 ms
71,804 KB
testcase_20 AC 395 ms
71,272 KB
testcase_21 AC 389 ms
71,784 KB
testcase_22 AC 395 ms
72,276 KB
testcase_23 AC 397 ms
70,984 KB
testcase_24 AC 394 ms
71,024 KB
testcase_25 AC 391 ms
71,136 KB
testcase_26 AC 394 ms
71,920 KB
testcase_27 AC 370 ms
39,488 KB
testcase_28 AC 353 ms
40,132 KB
testcase_29 AC 361 ms
39,708 KB
testcase_30 AC 356 ms
39,428 KB
testcase_31 AC 355 ms
39,476 KB
testcase_32 AC 57 ms
30,804 KB
testcase_33 AC 57 ms
30,900 KB
testcase_34 AC 58 ms
30,480 KB
testcase_35 AC 57 ms
30,564 KB
testcase_36 AC 59 ms
30,656 KB
testcase_37 AC 24 ms
19,536 KB
testcase_38 AC 266 ms
72,140 KB
testcase_39 AC 270 ms
71,788 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];
    unordered_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