結果

問題 No.957 植林
ユーザー comi_likecomi_like
提出日時 2021-05-16 22:16:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 363 ms / 2,000 ms
コード長 2,983 bytes
コンパイル時間 5,109 ms
コンパイル使用メモリ 235,212 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2024-04-15 13:00:42
合計ジャッジ時間 15,337 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 42 ms
8,916 KB
testcase_04 AC 39 ms
8,624 KB
testcase_05 AC 45 ms
9,192 KB
testcase_06 AC 45 ms
9,320 KB
testcase_07 AC 41 ms
8,792 KB
testcase_08 AC 37 ms
9,144 KB
testcase_09 AC 37 ms
9,140 KB
testcase_10 AC 40 ms
9,208 KB
testcase_11 AC 38 ms
9,008 KB
testcase_12 AC 38 ms
8,992 KB
testcase_13 AC 34 ms
7,980 KB
testcase_14 AC 42 ms
9,320 KB
testcase_15 AC 37 ms
9,028 KB
testcase_16 AC 34 ms
7,856 KB
testcase_17 AC 36 ms
8,892 KB
testcase_18 AC 258 ms
8,888 KB
testcase_19 AC 261 ms
9,032 KB
testcase_20 AC 286 ms
9,296 KB
testcase_21 AC 291 ms
9,304 KB
testcase_22 AC 302 ms
9,572 KB
testcase_23 AC 318 ms
9,580 KB
testcase_24 AC 339 ms
9,596 KB
testcase_25 AC 363 ms
9,744 KB
testcase_26 AC 350 ms
9,736 KB
testcase_27 AC 356 ms
9,740 KB
testcase_28 AC 362 ms
9,740 KB
testcase_29 AC 357 ms
9,740 KB
testcase_30 AC 355 ms
9,868 KB
testcase_31 AC 257 ms
8,892 KB
testcase_32 AC 263 ms
9,032 KB
testcase_33 AC 289 ms
9,168 KB
testcase_34 AC 299 ms
9,428 KB
testcase_35 AC 302 ms
9,312 KB
testcase_36 AC 330 ms
9,704 KB
testcase_37 AC 346 ms
9,600 KB
testcase_38 AC 351 ms
9,744 KB
testcase_39 AC 354 ms
9,736 KB
testcase_40 AC 352 ms
9,740 KB
testcase_41 AC 27 ms
9,608 KB
testcase_42 AC 25 ms
9,612 KB
testcase_43 AC 56 ms
9,744 KB
testcase_44 AC 57 ms
9,608 KB
testcase_45 AC 2 ms
6,940 KB
testcase_46 AC 2 ms
6,940 KB
testcase_47 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#include<atcoder/all>
using namespace atcoder;
typedef long long ll;
const long long INF = 1LL<<60;
const double PI = acos(-1.0);
/*const double PI = atan2(0.0,-1.0)*/
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep1(i,aa,n) for(ll i = aa; i <= (ll)(n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define ar_init(aa,val) rep(i,aa.size()) aa[i]=val;
#define v2d(aa,val1,val2,ini) vector<vector<ll>> aa(val1,vector<ll>(val2,ini));
#define pqe priority_queue<ll>
#define pqeg priority_queue<ll,vector<ll>,greater<ll>>
#define lcin(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define eout(...) COU(__VA_ARGS__);
#define sout(...) SCOU(__VA_ARGS__);
#define scin(...) string __VA_ARGS__;CINT(__VA_ARGS__)
#define lb(aa,val) lower_bound(ALL(aa),val)
#define pb push_back
#define mkp make_pair
ll kaijou(ll e){ll r=1;rep(i,e){r*=(i+1);}return r;}

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}

void COU(){}
template <class Head,class... Tail>
void COU(Head&& head,Tail&&... tail){
    cout<<head<<endl;
    COU(move(tail)...);
}

void SCOU(){}
template <class Head,class... Tail>
void SCOU(Head&& head,Tail&&... tail){
    cout<<head<<" ";
    SCOU(move(tail)...);
}

template <class T = ll>
T IN(){T x;cin>>x;return (x);}

using pii = pair<ll,ll>;
using v2 = vector<vector<ll>>;
using v1 = vector<ll>;
using v2p = vector<vector<pii>>;
using v1p = vector<pii>;
const ll mo=1000000007;
//const ll mo=998244353;

v2 mat_pow(v2 en,ll n){
ll si=en.size();
//n==0のときreturn単位行列
if(n==0){
rep(i,en.size()) rep(k,en.size()){
if(i==k){
en[i][k]=1;
}else{
en[i][k]=0;
}
}
return en; 
}

auto dfs = [&](auto self,ll ko) -> v2 {
if(ko==1){
return en;
}

auto e=self(self,ko/2);
v2d(res,si,si,0);
rep(i,res.size()){
rep(k,res.size()){
rep(m,res.size()){
res[i][k]+=e[i][m]*e[m][k]%mo;
res[i][k]%=mo;
}
}
}
v2d(rr,si,si,0);
if(ko%2){
rep(i,res.size()){
rep(k,res.size()){
rep(m,res.size()){
rr[i][k]+=res[i][m]*en[m][k]%mo;
rr[i][k]%=mo;
}
}
}
return rr;
}
return res;
};

return dfs(dfs,n);
}


ll mod_pow(ll N,ll n){
if(n==0) return 1;
ll hh;
hh=n%2;
int tt=mod_pow(N,n/2);
if(hh==0)return tt%mo*tt%mo;
else {return tt%mo*tt%mo*N%mo;}
}


int main(){

//cout<<fixed<<setprecision(15);

lcin(h,w);
mf_graph<ll> graph(h+w+100);
v2d(gg,h,w,0); 
v1 rr(h);
v1 cc(w);
ll s=h+w+50;
ll t=h+w+50+1;
v1 sum(h,0);
ll sum11=0;

rep(i,h)rep(k,w){
cin>>gg[i][k];
sum[i]+=gg[i][k];
graph.add_edge(i,h+k,gg[i][k]);
}

rep(i,h){
cin>>rr[i];
sum11+=rr[i];
}
rep(i,w){
cin>>cc[i];
sum11+=cc[i];
}

rep(i,h){
graph.add_edge(s,i,sum[i]);
graph.add_edge(i,t,rr[i]);
}

rep(i,w){
graph.add_edge(s,h+i,0);
graph.add_edge(h+i,t,cc[i]);
}

eout(sum11-graph.flow(s,t));




}
0