結果

問題 No.957 植林
ユーザー bokusunnybokusunny
提出日時 2022-05-01 23:48:50
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 356 ms / 2,000 ms
コード長 1,080 bytes
コンパイル時間 2,337 ms
コンパイル使用メモリ 213,576 KB
実行使用メモリ 9,440 KB
最終ジャッジ日時 2023-09-13 16:48:44
合計ジャッジ時間 13,217 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 22 ms
8,604 KB
testcase_04 AC 21 ms
8,176 KB
testcase_05 AC 22 ms
8,396 KB
testcase_06 AC 24 ms
8,752 KB
testcase_07 AC 22 ms
8,300 KB
testcase_08 AC 17 ms
8,400 KB
testcase_09 AC 16 ms
8,520 KB
testcase_10 AC 18 ms
8,648 KB
testcase_11 AC 17 ms
8,428 KB
testcase_12 AC 17 ms
8,524 KB
testcase_13 AC 14 ms
7,424 KB
testcase_14 AC 18 ms
8,672 KB
testcase_15 AC 16 ms
8,496 KB
testcase_16 AC 15 ms
7,412 KB
testcase_17 AC 15 ms
8,240 KB
testcase_18 AC 256 ms
8,368 KB
testcase_19 AC 271 ms
8,748 KB
testcase_20 AC 270 ms
8,592 KB
testcase_21 AC 284 ms
8,632 KB
testcase_22 AC 305 ms
9,128 KB
testcase_23 AC 312 ms
8,864 KB
testcase_24 AC 322 ms
9,012 KB
testcase_25 AC 349 ms
9,284 KB
testcase_26 AC 349 ms
9,200 KB
testcase_27 AC 350 ms
9,208 KB
testcase_28 AC 350 ms
9,172 KB
testcase_29 AC 346 ms
9,440 KB
testcase_30 AC 356 ms
9,288 KB
testcase_31 AC 257 ms
8,336 KB
testcase_32 AC 268 ms
8,756 KB
testcase_33 AC 273 ms
8,584 KB
testcase_34 AC 287 ms
8,756 KB
testcase_35 AC 296 ms
9,000 KB
testcase_36 AC 311 ms
8,896 KB
testcase_37 AC 321 ms
9,000 KB
testcase_38 AC 350 ms
9,196 KB
testcase_39 AC 351 ms
9,268 KB
testcase_40 AC 346 ms
9,196 KB
testcase_41 AC 14 ms
9,428 KB
testcase_42 AC 14 ms
9,284 KB
testcase_43 AC 20 ms
9,132 KB
testcase_44 AC 20 ms
9,220 KB
testcase_45 AC 2 ms
4,376 KB
testcase_46 AC 2 ms
4,376 KB
testcase_47 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define bokusunny ios::sync_with_stdio(false), cin.tie(nullptr);

#include <atcoder/maxflow>
using namespace atcoder;

void solve() {
  int H, W;
  cin >> H >> W;
  using Grid = vector<vector<int>>;
  Grid grid(H, vector<int>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> grid[i][j];
    }
  }
  vector<int> R(H);
  for (int i = 0; i < H; i++) cin >> R[i];
  vector<int> C(W);
  for (int i = 0; i < W; i++) cin >> C[i];

  using Cap = long long;
  mf_graph<Cap> G(H + W + 2);
  const int s = H + W, t = H + W + 1;
  for (int h = 0; h < H; h++) {
    G.add_edge(s, h, R[h]);
    long long tot = 0;
    for (auto &g : grid[h]) tot += g;
    G.add_edge(h, t, tot);
  }
  for (int w = 0; w < W; w++) {
    G.add_edge(s, H + w, C[w]);
    for (int h = 0; h < H; h++) {
      G.add_edge(H + w, h, grid[h][w]);
    }
  }

  auto ans = accumulate(R.begin(), R.end(), 0LL) + accumulate(C.begin(), C.end(), 0LL) - G.flow(s, t);
  cout << ans << endl;
}

int main() {
  bokusunny;
  solve();

  return 0;
}
0