結果

問題 No.1479 Matrix Eraser
ユーザー hir355hir355
提出日時 2021-04-16 21:41:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 2,070 bytes
コンパイル時間 2,453 ms
コンパイル使用メモリ 215,876 KB
実行使用メモリ 22,888 KB
最終ジャッジ日時 2023-09-15 23:58:18
合計ジャッジ時間 9,735 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 8 ms
14,912 KB
testcase_01 AC 7 ms
14,984 KB
testcase_02 AC 8 ms
14,632 KB
testcase_03 AC 7 ms
14,896 KB
testcase_04 AC 7 ms
14,840 KB
testcase_05 AC 8 ms
14,792 KB
testcase_06 AC 7 ms
14,956 KB
testcase_07 AC 2,198 ms
17,180 KB
testcase_08 TLE -
testcase_09 -- -
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 <atcoder/maxflow>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
const long long INF_LL = 2000000000000000000LL;
const int INF = 2000000000;
const long long MOD = 1000000007;
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

typedef vector<vector<edge>> graph;

// using mint = modint998244353;

int main(){
    int h, w;
    cin >> h >> w;
    vector<vector<int>> a(h, vector<int>(w));
    rep(i, h) rep(j, w) cin >> a[i][j];
    vector<vector<pair<int, int>>> t(500000);
    rep(i, h){
        rep(j, w){
            if(a[i][j] > 0) t[a[i][j] - 1].push_back({i, j});
        }
    }
    mf_graph<int> g(h + w + 2);
    rep(i, h) g.add_edge(h + w, i, 1);
    rep(i, w) g.add_edge(i + h, h + w + 1, 1);
    int idx = h + w;
    int ans = 0;
    for(int i = 499999; i >= 0; i--){
        rep(j, t[i].size()){
            g.add_edge(t[i][j].first, t[i][j].second + h, 1);
        }
        if(t[i].size() > 0) {
            ans += g.flow(h + w, h + w + 1);
            g.flow(h + w + 1, h + w);
            REP(j, idx, idx + t[i].size()){
                g.change_edge(j, 0, 0);
            }
        }
        idx += t[i].size();
    }
    cout << ans << endl;
}
0