結果

問題 No.2095 High Rise
ユーザー 沙耶花沙耶花
提出日時 2022-10-07 21:40:38
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 853 bytes
コンパイル時間 17,322 ms
コンパイル使用メモリ 338,024 KB
最終ジャッジ日時 2025-02-07 23:04:08
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 19 TLE * 1 MLE * 4
権限があれば一括ダウンロードができます

ソースコード

diff #

#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


int main(){
	
	int N,M;
	cin>>N>>M;
	
	vector a(N,vector<long long>(M));
	rep(i,N){
		rep(j,M){
			cin>>a[i][j];
		}
	}
	
	if(N==1){
		cout<<0<<endl;
		return 0;
		
	}
	
	mcf_graph<long long,long long> G(N*M*2);
	
	rep(i,N){
		rep(j,M){
			if(j!=M-1)G.add_edge(i*M+j,i*M+j+1,1,0);
			if(j!=0)G.add_edge(i*M+j,i*M+j-1,1,0);
			
			G.add_edge(N*M + i*M+j, i*M+j,1,0);
			G.add_edge(i*M+j,N*M+i*M+j,1,a[i][j]);
			if(i!=N-1){
				G.add_edge(N*M+i*M+j, N*M+(i+1)*M+j, 1,a[i+1][j]);
			}
		}
	}
	auto ans = G.flow(0,N*M-1,1);
	cout<<ans.second<<endl;
	//cout<<G.flow(0,N*M-1,1).second<<endl;
	
	return 0;
}
0