結果
| 問題 |
No.2328 Build Walls
|
| コンテスト | |
| ユーザー |
Haa
|
| 提出日時 | 2023-05-28 15:05:38 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 865 ms / 3,000 ms |
| コード長 | 1,241 bytes |
| コンパイル時間 | 5,774 ms |
| コンパイル使用メモリ | 247,400 KB |
| 実行使用メモリ | 509,424 KB |
| 最終ジャッジ日時 | 2024-12-27 04:33:48 |
| 合計ジャッジ時間 | 13,951 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
template<typename T> bool chmax(T& x, const T& y){return (x<y)?(x=y,true):false;};
template<typename T> bool chmin(T& x, const T& y){return (x>y)?(x=y,true):false;};
constexpr ll MOD=998244353;
constexpr ll INF=2e18;
const int dx[8]={1,0,-1,0,1,1,-1,-1}, dy[8]={0,1,0,-1,1,-1,1,-1};
int main(){
int h, w; cin >> h >> w; h-=2;
VVI a(h,VI(w));
REP(i,h)REP(j,w) cin >> a[i][j];
mcf_graph<int,int> g(h*w+2);
int s=h*w, t=h*w+1;
REP(i,h)REP(j,w){
if(a[i][j]==-1)
continue;
REP(k,8){
int ti=i+dx[k], tj=j+dy[k];
if(ti<0||ti>=h||tj<0||tj>=w)
continue;
g.add_edge(i*w+j,ti*w+tj,1,a[i][j]);
if(j==0)
g.add_edge(s,i*w+j,1,0);
else if(j==w-1)
g.add_edge(i*w+j,t,1,a[i][j]);
}
}
auto ans=g.flow(s,t,1);
if(ans.first==0)
cout << -1 << endl;
else
cout << ans.second << endl;
return 0;
}
Haa