結果

問題 No.957 植林
ユーザー t98slidert98slider
提出日時 2023-11-13 23:41:23
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 418 ms / 2,000 ms
コード長 932 bytes
コンパイル時間 4,534 ms
コンパイル使用メモリ 270,624 KB
実行使用メモリ 9,400 KB
最終ジャッジ日時 2023-11-13 23:41:38
合計ジャッジ時間 14,986 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 20 ms
8,640 KB
testcase_04 AC 20 ms
8,512 KB
testcase_05 AC 22 ms
8,776 KB
testcase_06 AC 23 ms
9,024 KB
testcase_07 AC 21 ms
8,656 KB
testcase_08 AC 17 ms
8,728 KB
testcase_09 AC 17 ms
8,728 KB
testcase_10 AC 18 ms
8,924 KB
testcase_11 AC 17 ms
8,856 KB
testcase_12 AC 16 ms
8,716 KB
testcase_13 AC 15 ms
7,748 KB
testcase_14 AC 19 ms
9,144 KB
testcase_15 AC 16 ms
8,760 KB
testcase_16 AC 15 ms
7,740 KB
testcase_17 AC 16 ms
8,508 KB
testcase_18 AC 284 ms
8,744 KB
testcase_19 AC 302 ms
8,868 KB
testcase_20 AC 326 ms
9,000 KB
testcase_21 AC 323 ms
9,008 KB
testcase_22 AC 349 ms
9,128 KB
testcase_23 AC 370 ms
9,264 KB
testcase_24 AC 381 ms
9,392 KB
testcase_25 AC 401 ms
9,400 KB
testcase_26 AC 394 ms
9,400 KB
testcase_27 AC 395 ms
9,400 KB
testcase_28 AC 396 ms
9,400 KB
testcase_29 AC 395 ms
9,400 KB
testcase_30 AC 395 ms
9,400 KB
testcase_31 AC 286 ms
8,744 KB
testcase_32 AC 300 ms
8,868 KB
testcase_33 AC 326 ms
9,000 KB
testcase_34 AC 323 ms
9,008 KB
testcase_35 AC 349 ms
9,128 KB
testcase_36 AC 371 ms
9,264 KB
testcase_37 AC 386 ms
9,392 KB
testcase_38 AC 418 ms
9,400 KB
testcase_39 AC 393 ms
9,400 KB
testcase_40 AC 395 ms
9,400 KB
testcase_41 AC 14 ms
9,400 KB
testcase_42 AC 14 ms
9,400 KB
testcase_43 AC 20 ms
9,400 KB
testcase_44 AC 21 ms
9,400 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>
#include <atcoder/all>
using namespace std;
using ll = long long;

template<class T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h, w;
    cin >> h >> w;
    vector<vector<int>> G(h, vector<int>(w));
    vector<int> R(h), C(w);
    cin >> G >> R >> C;
    atcoder::mf_graph<ll> g(h + w + 2);
    int src = h + w, sink = src + 1;
    ll ans = 0;
    for(int y = 0; y < h; y++){
        ll s = accumulate(G[y].begin(), G[y].end(), 0ll);
        ll mn = min((ll)(R[y]), s);
        ans += R[y] - mn;
        g.add_edge(src, y, s - mn);
        for(int x = 0; x < w; x++){
            g.add_edge(y, x + h, G[y][x]);
        }
    }
    for(int x = 0; x < w; x++){
        g.add_edge(x + h, sink, C[x]);
        ans += C[x];
    }
    ans -= g.flow(src, sink);
    cout << ans << '\n';
}
0