結果
問題 | No.957 植林 |
ユーザー |
![]() |
提出日時 | 2023-06-03 14:53:44 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 418 ms / 2,000 ms |
コード長 | 921 bytes |
コンパイル時間 | 5,298 ms |
コンパイル使用メモリ | 259,756 KB |
最終ジャッジ日時 | 2025-02-13 22:20:47 |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 45 |
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001 #define Inf48 5000000000000 int main(){ int h,w; cin>>h>>w; vector g(h,vector<long long>(w)); long long ans = 0; rep(i,h){ rep(j,w){ cin>>g[i][j]; ans += g[i][j]; } } vector<long long> rc0(h+w,Inf48); auto rc1 = rc0; rep(i,h+w){ long long t; cin>>t; rc1[i] -= t; } rep(i,h){ rep(j,w){ rc0[i] -= g[i][j]; } } mf_graph<long long> G(h+w + 2); int s = (h+w); int t = s+1; rep(i,h+w){ G.add_edge(s,i,rc0[i]); G.add_edge(i,t,rc1[i]); } rep(i,h){ rep(j,w){ G.add_edge(h+j,i,g[i][j]); } } //cout<<ans<<endl; ans += G.flow(s,t); //cout<<ans<<endl; ans -= Inf48 * (h+w); ans *= -1; cout<<ans<<endl; return 0; }