結果

問題 No.957 植林
ユーザー shin3110shin3110
提出日時 2023-11-12 19:18:39
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 462 ms / 2,000 ms
コード長 2,595 bytes
コンパイル時間 4,020 ms
コンパイル使用メモリ 241,180 KB
実行使用メモリ 9,016 KB
最終ジャッジ日時 2023-11-12 19:18:55
合計ジャッジ時間 15,391 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 36 ms
8,328 KB
testcase_04 AC 35 ms
8,212 KB
testcase_05 AC 40 ms
8,448 KB
testcase_06 AC 41 ms
8,672 KB
testcase_07 AC 37 ms
8,352 KB
testcase_08 AC 33 ms
8,408 KB
testcase_09 AC 32 ms
8,524 KB
testcase_10 AC 34 ms
8,576 KB
testcase_11 AC 33 ms
8,524 KB
testcase_12 AC 33 ms
8,392 KB
testcase_13 AC 28 ms
7,572 KB
testcase_14 AC 36 ms
8,784 KB
testcase_15 AC 32 ms
8,440 KB
testcase_16 AC 29 ms
7,440 KB
testcase_17 AC 31 ms
8,208 KB
testcase_18 AC 314 ms
8,424 KB
testcase_19 AC 335 ms
8,548 KB
testcase_20 AC 364 ms
8,664 KB
testcase_21 AC 365 ms
8,656 KB
testcase_22 AC 385 ms
8,772 KB
testcase_23 AC 403 ms
8,892 KB
testcase_24 AC 433 ms
8,892 KB
testcase_25 AC 435 ms
9,016 KB
testcase_26 AC 438 ms
9,016 KB
testcase_27 AC 446 ms
9,016 KB
testcase_28 AC 435 ms
9,016 KB
testcase_29 AC 462 ms
9,016 KB
testcase_30 AC 438 ms
9,016 KB
testcase_31 AC 313 ms
8,424 KB
testcase_32 AC 335 ms
8,548 KB
testcase_33 AC 369 ms
8,664 KB
testcase_34 AC 362 ms
8,656 KB
testcase_35 AC 389 ms
8,772 KB
testcase_36 AC 411 ms
8,892 KB
testcase_37 AC 419 ms
8,892 KB
testcase_38 AC 437 ms
9,016 KB
testcase_39 AC 445 ms
9,016 KB
testcase_40 AC 439 ms
9,016 KB
testcase_41 AC 23 ms
9,016 KB
testcase_42 AC 23 ms
9,016 KB
testcase_43 AC 49 ms
9,016 KB
testcase_44 AC 49 ms
9,016 KB
testcase_45 AC 2 ms
6,676 KB
testcase_46 AC 2 ms
6,676 KB
testcase_47 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long

struct edge {
    int to, seq;
    ll cup;
};

class max_flow {
    public:
    int siz;
    vector<vector<edge>> side;
    vector<int> dist;

    max_flow (int n) {
        siz = n;
        side.assign(siz, {});
        return ;
    }

    void set(int pos, int to, ll x) {
        int a = side[to].size();
        int b = side[pos].size();
        side[pos].push_back(edge{to, a, x});
        side[to].push_back(edge{pos, b, 0});
        return ;
    }

    void bfs(int s) {
        dist.assign(siz, -1);
        dist[s] = 0;
        queue<int> q;
        q.push(s);
        while(!q.empty()) {
            int pos = q.front(); q.pop();
            for(int i=0; i<side[pos].size(); i++) {
                edge e = side[pos][i];
                if(e.cup <= 0) continue;
                if(dist[e.seq] >= 0) continue;
                dist[e.seq] = dist[pos]+1;
                q.push(e.seq);
            }
        }
    }

    ll dfs(int pos, int goal, ll F) {
        if(pos == goal) return F;
        return 0;
    }

    ll len(int s, int t) {
        ll res = 0;
        while(1) {
            bfs(s);
            if(dist[t] < 0) return res;
        }
        return res;
    }
};

/*
signed main() {
    int h, w; cin >> h >> w;
    int ax = h+w+1;
    max_flow F(ax+1);
    vector<ll> c(h+1, 0);
    for(int i=0; i<h*w; i++) {
        ll g; cin >> g;
        int x = i/w;
        c[x+1] += g;
        int y = i%w;
        F.set(x+1, h+y+1, g);
    }
    ll ans = 0;
    for(int j=1; j<=h; j++) {
        ll r; cin >> r;
        r -= c[j];
        if(r < 0) F.set(0, j, -r);
        else {
            ans += r;
            F.set(j, ax, r);
        }
    }
    for(int i=1; i<=w; i++) {
        ll r; cin >> r;
        F.set(h+i, ax, r);
        ans += r;
    }
    ans -= F.len(0, ax);
    cout << ans << endl;
} */

signed main() {
    int h, w; cin >> h >> w;
    int ax = h+w+1;
    mf_graph<ll> F(ax+1);
    vector<ll> c(h+1, 0);
    for(int i=0; i<h*w; i++) {
        ll g; cin >> g;
        int x = i/w;
        c[x+1] += g;
        int y = i%w;
        F.add_edge(x+1, h+y+1, g);
    }
    ll ans = 0;
    for(int j=1; j<=h; j++) {
        ll r; cin >> r;
        r -= c[j];
        if(r < 0) F.add_edge(0, j, -r);
        else {
            ans += r;
            F.add_edge(j, ax, r);
        }
    }
    for(int i=1; i<=w; i++) {
        ll r; cin >> r;
        F.add_edge(h+i, ax, r);
        ans += r;
    }
    ans -= F.flow(0, ax);
    cout << ans << endl;
}
0