結果

問題 No.2328 Build Walls
ユーザー HaaHaa
提出日時 2023-05-28 15:05:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 811 ms / 3,000 ms
コード長 1,241 bytes
コンパイル時間 4,263 ms
コンパイル使用メモリ 245,480 KB
実行使用メモリ 510,376 KB
最終ジャッジ日時 2023-08-27 11:23:42
合計ジャッジ時間 13,175 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,384 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,376 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 160 ms
108,692 KB
testcase_14 AC 197 ms
122,204 KB
testcase_15 AC 152 ms
87,224 KB
testcase_16 AC 30 ms
19,536 KB
testcase_17 AC 156 ms
85,400 KB
testcase_18 AC 6 ms
5,216 KB
testcase_19 AC 21 ms
12,568 KB
testcase_20 AC 16 ms
11,020 KB
testcase_21 AC 87 ms
36,112 KB
testcase_22 AC 296 ms
187,304 KB
testcase_23 AC 589 ms
322,512 KB
testcase_24 AC 552 ms
296,664 KB
testcase_25 AC 582 ms
317,736 KB
testcase_26 AC 478 ms
243,464 KB
testcase_27 AC 528 ms
282,248 KB
testcase_28 AC 136 ms
31,500 KB
testcase_29 AC 584 ms
322,924 KB
testcase_30 AC 287 ms
200,028 KB
testcase_31 AC 265 ms
169,964 KB
testcase_32 AC 528 ms
278,300 KB
testcase_33 AC 811 ms
510,376 KB
testcase_34 AC 301 ms
208,612 KB
testcase_35 AC 625 ms
401,612 KB
testcase_36 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0