結果

問題 No.2328 Build Walls
ユーザー cho435cho435
提出日時 2023-05-28 14:51:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,280 bytes
コンパイル時間 2,356 ms
コンパイル使用メモリ 209,352 KB
実行使用メモリ 10,984 KB
最終ジャッジ日時 2023-08-27 10:45:26
合計ジャッジ時間 6,376 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 WA -
testcase_13 AC 77 ms
6,964 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 11 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 61 ms
7,000 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 120 ms
10,664 KB
testcase_29 WA -
testcase_30 AC 145 ms
10,648 KB
testcase_31 AC 140 ms
10,692 KB
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 149 ms
10,984 KB
testcase_35 WA -
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for (int i=0;i<(int)(n);i++)

int main(){
  int h,w;
  cin>>h>>w;
  vector<vector<int>> a(h-2,vector<int>(w));
  rep(i,h-2) rep(j,w) cin>>a.at(i).at(j);
  vector<vector<ll>> dp(h-2,vector<ll>(w+1,1e18));
  rep(i,h-2) dp.at(i).at(0)=a.at(i).at(0);
  rep(j,w-1){
    rep(i,h-2){
      if(a.at(i).at(j+1)==-1){
        dp.at(i).at(j+1)=-1;
        continue;
      }
      if(dp.at(i).at(j)!=-1) dp.at(i).at(j+1)=min(dp.at(i).at(j+1),dp.at(i).at(j)+a.at(i).at(j+1));
      if(i>0&&dp.at(i-1).at(j)!=-1) dp.at(i).at(j+1)=min(dp.at(i).at(j+1),dp.at(i-1).at(j)+a.at(i).at(j+1));
      if(i<h-3&&dp.at(i+1).at(j)!=-1) dp.at(i).at(j+1)=min(dp.at(i).at(j+1),dp.at(i+1).at(j)+a.at(i).at(j+1));
    }
    rep(i,h-3){
      if(dp.at(i+1).at(j)==-1) continue;
      if(a.at(i+1).at(j+1)==-1) continue;
      dp.at(i+1).at(j+1)=min(dp.at(i+1).at(j+1),dp.at(i+1).at(j)+a.at(i+1).at(j+1));
    }
    for(int i=h-4;i>=0;i--){
      if(dp.at(i+1).at(j+1)==-1) continue;
      if(a.at(i+1).at(j)==-1) continue;
      dp.at(i+1).at(j)=min(dp.at(i+1).at(j),dp.at(i+1).at(j+1)+a.at(i+1).at(j));
    }
  }
  ll ans=1e18;
  rep(i,h-2){
    ans=min(ans,dp.at(i).at(w-1));
  }
  if(ans==1e18) ans=-1;
  cout<<ans<<endl;
}
0