結果

問題 No.957 植林
ユーザー shin3110shin3110
提出日時 2023-11-12 11:32:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,781 bytes
コンパイル時間 2,200 ms
コンパイル使用メモリ 181,088 KB
実行使用メモリ 23,000 KB
最終ジャッジ日時 2023-11-12 11:32:50
合計ジャッジ時間 8,155 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
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 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
testcase_46 -- -
testcase_47 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define ll long long

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

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

    max_flow (int n) {
        siz = n;
        side.assign(siz, {});
        used.assign(siz, false);
        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 ;
    }

    ll dfs(int pos, int goal, ll F) {
        if(pos == goal) return F;
        used[pos] = true;
        for(int i=0; i<side[pos].size(); i++) {
            if(side[pos][i].cup == 0) continue;
            if(used[side[pos][i].to]) continue;
            ll G = dfs(side[pos][i].to, goal, min(F, side[pos][i].cup));
            if(G > 0) {
                side[pos][i].cup -= G;
                side[side[pos][i].to][side[pos][i].seq].cup += G;
                return G;
            }
        }
        return 0;
    }

    ll len(int s, int t) {
        ll res = 0;
        while(1) {
            used.assign(siz, false);
            ll F = dfs(s, t, 1e18);
            if(F == 0) break;
            res += F;
        }
        return res;
    }
};

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