結果
問題 |
No.2328 Build Walls
|
ユーザー |
![]() |
提出日時 | 2023-05-28 14:07:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 973 bytes |
コンパイル時間 | 3,971 ms |
コンパイル使用メモリ | 257,752 KB |
最終ジャッジ日時 | 2025-02-13 10:54:24 |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 17 TLE * 17 |
ソースコード
#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 H,W; cin>>H>>W; vector a(H,vector<int>(W,-1)); rep(i,H){ if(i==0||i==H-1)continue; rep(j,W){ cin>>a[i][j]; } } mf_graph<long long> G(H*W*2+2); int S = H*W*2; int T= H*W*2+1; rep(i,H){ rep(j,W){ if(a[i][j]!=-1)G.add_edge(i*W+j,i*W+j+H*W,a[i][j]); else G.add_edge(i*W+j,i*W+j+H*W,Inf32); } } vector<int> dx = {1,-1,0,0},dy = {0,0,1,-1}; rep(i,H){ rep(j,W){ rep(k,4){ int ii = i+dx[k],jj = j+dy[k]; if(ii<0||ii>=H||jj<0||jj>=W)continue; G.add_edge(i*W+j+H*W,ii*W+jj,Inf32); } } } rep(i,W){ G.add_edge(S,0*W+i,Inf32); G.add_edge((H-1)*W+i+H*W,T,Inf32); } long long ans = G.flow(S,T); if(ans>=Inf32)ans = -1; cout<<ans<<endl; return 0; }