結果

問題 No.957 植林
ユーザー bokusunnybokusunny
提出日時 2022-01-19 16:33:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 311 ms / 2,000 ms
コード長 1,220 bytes
コンパイル時間 2,605 ms
コンパイル使用メモリ 217,248 KB
実行使用メモリ 9,776 KB
最終ジャッジ日時 2024-05-02 19:47:54
合計ジャッジ時間 10,796 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 18 ms
8,904 KB
testcase_04 AC 18 ms
8,668 KB
testcase_05 AC 20 ms
8,964 KB
testcase_06 AC 22 ms
9,220 KB
testcase_07 AC 19 ms
8,684 KB
testcase_08 AC 14 ms
9,056 KB
testcase_09 AC 15 ms
9,052 KB
testcase_10 AC 16 ms
9,124 KB
testcase_11 AC 14 ms
9,056 KB
testcase_12 AC 14 ms
9,016 KB
testcase_13 AC 12 ms
7,472 KB
testcase_14 AC 15 ms
9,236 KB
testcase_15 AC 14 ms
8,920 KB
testcase_16 AC 12 ms
7,868 KB
testcase_17 AC 14 ms
8,672 KB
testcase_18 AC 215 ms
8,940 KB
testcase_19 AC 270 ms
9,056 KB
testcase_20 AC 264 ms
9,088 KB
testcase_21 AC 259 ms
9,216 KB
testcase_22 AC 268 ms
9,228 KB
testcase_23 AC 287 ms
9,480 KB
testcase_24 AC 299 ms
9,516 KB
testcase_25 AC 298 ms
9,648 KB
testcase_26 AC 307 ms
9,772 KB
testcase_27 AC 311 ms
9,648 KB
testcase_28 AC 305 ms
9,648 KB
testcase_29 AC 306 ms
9,772 KB
testcase_30 AC 311 ms
9,652 KB
testcase_31 AC 235 ms
8,940 KB
testcase_32 AC 241 ms
9,068 KB
testcase_33 AC 248 ms
9,212 KB
testcase_34 AC 251 ms
9,216 KB
testcase_35 AC 262 ms
9,352 KB
testcase_36 AC 273 ms
9,488 KB
testcase_37 AC 295 ms
9,640 KB
testcase_38 AC 303 ms
9,776 KB
testcase_39 AC 311 ms
9,652 KB
testcase_40 AC 307 ms
9,776 KB
testcase_41 AC 12 ms
9,648 KB
testcase_42 AC 12 ms
9,648 KB
testcase_43 AC 18 ms
9,524 KB
testcase_44 AC 19 ms
9,644 KB
testcase_45 AC 2 ms
5,376 KB
testcase_46 AC 2 ms
5,376 KB
testcase_47 AC 2 ms
5,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;
  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