結果

問題 No.957 植林
ユーザー bokusunnybokusunny
提出日時 2022-01-19 14:41:21
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,444 bytes
コンパイル時間 2,720 ms
コンパイル使用メモリ 215,664 KB
実行使用メモリ 26,192 KB
最終ジャッジ日時 2023-08-15 07:56:44
合計ジャッジ時間 9,632 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
26,192 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 101 ms
21,640 KB
testcase_04 AC 86 ms
21,392 KB
testcase_05 AC 93 ms
22,432 KB
testcase_06 AC 97 ms
23,040 KB
testcase_07 AC 93 ms
21,276 KB
testcase_08 AC 63 ms
22,076 KB
testcase_09 AC 60 ms
22,504 KB
testcase_10 AC 70 ms
23,852 KB
testcase_11 AC 65 ms
21,956 KB
testcase_12 AC 65 ms
22,744 KB
testcase_13 AC 51 ms
19,784 KB
testcase_14 AC 64 ms
23,780 KB
testcase_15 AC 60 ms
21,564 KB
testcase_16 AC 52 ms
20,444 KB
testcase_17 AC 54 ms
21,444 KB
testcase_18 TLE -
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 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 + H + W + 2);
  const int s = H * W + H + W;
  const int g = H * W + H + W + 1;
  const long long INF = 1LL << 60;

  auto to_num = [&](int h, int w) { return h * W + w; };

  for (int h = 0; h < H; h++) {
    for (int w = 0; w < W; w++) {
      G.add_edge(s, to_num(h, w), 0);
      G.add_edge(to_num(h, w), g, Cost[h][w]);
    }
  }
  for (int h = 0; h < H; h++) {
    int cur = H * W + h;
    G.add_edge(s, cur, R[h]);
    G.add_edge(cur, g, 0);
    for (int w = 0; w < W; w++) {
      G.add_edge(cur, to_num(h, w), INF);
    }
  }
  for (int w = 0; w < W; w++) {
    int cur = H * W + H + w;
    G.add_edge(s, cur, C[w]);
    G.add_edge(cur, g, 0);
    for (int h = 0; h < H; h++) {
      G.add_edge(cur, to_num(h, w), INF);
    }
  }

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

int main() {
  bokusunny;
  solve();

  return 0;
}
0