結果
問題 |
No.957 植林
|
ユーザー |
|
提出日時 | 2023-11-13 23:41:23 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 336 ms / 2,000 ms |
コード長 | 932 bytes |
コンパイル時間 | 5,187 ms |
コンパイル使用メモリ | 259,152 KB |
最終ジャッジ日時 | 2025-02-17 21:57:38 |
ジャッジサーバーID (参考情報) |
judge1 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#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'; }