結果

問題 No.957 植林
ユーザー bokusunnybokusunny
提出日時 2022-01-19 16:33:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 420 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 2,710 ms
コンパイル使用メモリ 216,596 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2023-08-15 07:57:54
合計ジャッジ時間 13,347 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 21 ms
9,012 KB
testcase_04 AC 21 ms
8,632 KB
testcase_05 AC 23 ms
8,840 KB
testcase_06 AC 24 ms
9,088 KB
testcase_07 AC 22 ms
8,556 KB
testcase_08 AC 18 ms
8,688 KB
testcase_09 AC 17 ms
8,708 KB
testcase_10 AC 19 ms
8,996 KB
testcase_11 AC 18 ms
8,820 KB
testcase_12 AC 18 ms
8,704 KB
testcase_13 AC 15 ms
7,512 KB
testcase_14 AC 19 ms
9,432 KB
testcase_15 AC 17 ms
8,796 KB
testcase_16 AC 15 ms
7,828 KB
testcase_17 AC 16 ms
8,548 KB
testcase_18 AC 301 ms
8,824 KB
testcase_19 AC 313 ms
8,948 KB
testcase_20 AC 338 ms
8,976 KB
testcase_21 AC 340 ms
9,148 KB
testcase_22 AC 358 ms
9,424 KB
testcase_23 AC 384 ms
9,312 KB
testcase_24 AC 398 ms
9,272 KB
testcase_25 AC 413 ms
9,540 KB
testcase_26 AC 417 ms
9,680 KB
testcase_27 AC 414 ms
9,692 KB
testcase_28 AC 420 ms
9,684 KB
testcase_29 AC 414 ms
9,656 KB
testcase_30 AC 415 ms
9,540 KB
testcase_31 AC 300 ms
8,824 KB
testcase_32 AC 315 ms
9,128 KB
testcase_33 AC 340 ms
8,972 KB
testcase_34 AC 345 ms
9,096 KB
testcase_35 AC 359 ms
9,432 KB
testcase_36 AC 382 ms
9,232 KB
testcase_37 AC 400 ms
9,516 KB
testcase_38 AC 417 ms
9,528 KB
testcase_39 AC 411 ms
9,672 KB
testcase_40 AC 419 ms
9,544 KB
testcase_41 AC 15 ms
9,684 KB
testcase_42 AC 14 ms
9,728 KB
testcase_43 AC 21 ms
9,656 KB
testcase_44 AC 21 ms
9,548 KB
testcase_45 AC 2 ms
4,380 KB
testcase_46 AC 2 ms
4,380 KB
testcase_47 AC 1 ms
4,380 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;
  vector Cost(H, vector<long long>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> Cost[i][j];
    }
  }
  vector<long long> R(H), C(W);
  for (int i = 0; i < H; i++) cin >> R[i];
  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;
  const int g = H + W + 1;

  for (int h = 0; h < H; h++) {
    int cur = h;
    long long sum = 0;
    for (int w = 0; w < W; w++) sum += Cost[h][w];
    G.add_edge(s, cur, sum);
    G.add_edge(cur, g, R[h]);
  }
  for (int w = 0; w < W; w++) {
    int cur = H + w;
    G.add_edge(s, cur, 0);
    G.add_edge(cur, g, C[w]);
  }
  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      int from = h;
      int to = H + w;
      G.add_edge(from, to, Cost[h][w]);
    }
  }

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

int main() {
  bokusunny;
  solve();

  return 0;
}
0