結果

問題 No.2328 Build Walls
ユーザー FplusFplusFFplusFplusF
提出日時 2023-05-28 15:52:08
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,555 bytes
コンパイル時間 2,273 ms
コンパイル使用メモリ 205,260 KB
実行使用メモリ 13,308 KB
最終ジャッジ日時 2023-08-27 13:09:21
合計ジャッジ時間 5,930 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 36 ms
8,392 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 6 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 29 ms
7,760 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 55 ms
13,076 KB
testcase_29 WA -
testcase_30 AC 70 ms
13,080 KB
testcase_31 AC 67 ms
12,992 KB
testcase_32 WA -
testcase_33 AC 857 ms
13,108 KB
testcase_34 AC 72 ms
13,120 KB
testcase_35 AC 101 ms
13,108 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll,ll>;
const ll INF=(1ll<<60);
#define rep(i,n) for (ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(),v.end()
template<class T> void chmin(T &a,T b){
    if(a>b){
        a=b;
    }
}
template<class T> void chmax(T &a,T b){
    if(a<b){
        a=b;
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll h,w;
    cin >> h >> w;
    h-=2;
    vector<vector<ll>> a(h,vector<ll>(w));
    rep(i,h){
        rep(j,w){
            cin >> a[i][j];
        }
    }
    vector<vector<ll>> dp(h,vector<ll>(w+1,INF));
    rep(i,h) dp[i][0]=0;
    rep(j,w){
        rep(i,h){
            if(a[i][j]==-1) continue;
            ll now=a[i][j];
            for(ll k=i-2;0<=k;k--){
                if(a[k+1][j]==-1) break;
                now+=a[k+1][j];
                for(ll kk=max(0ll,i-1);kk<=min(h-1,i+1);kk++){
                    chmin(dp[kk][j+1],dp[i][j]+now);
                }
            }
            for(ll k=max(0ll,i-1);k<=min(h-1,i+1);k++){
                chmin(dp[k][j+1],dp[i][j]+a[i][j]);
            }
            now=a[i][j];
            for(ll k=i+2;k<h;k++){
                if(a[k-1][j]==-1) break;
                now+=a[k-1][j];
                for(ll kk=max(0ll,i-1);kk<=min(h-1,i+1);kk++){
                    chmin(dp[kk][j+1],dp[i][j]+now);
                }
            }
        }
    }
    ll ans=INF;
    rep(i,h) chmin(ans,dp[i][w]);
    if(ans==INF) cout << "-1\n";
    else cout << ans << '\n';
}
0