結果

問題 No.2328 Build Walls
ユーザー MMMM
提出日時 2023-05-28 14:34:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 924 bytes
コンパイル時間 1,658 ms
コンパイル使用メモリ 169,648 KB
実行使用メモリ 13,356 KB
最終ジャッジ日時 2023-08-27 10:07:25
合計ジャッジ時間 5,512 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 69 ms
8,428 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 60 ms
7,932 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 119 ms
13,068 KB
testcase_29 WA -
testcase_30 AC 128 ms
13,216 KB
testcase_31 AC 128 ms
13,080 KB
testcase_32 WA -
testcase_33 AC 138 ms
13,004 KB
testcase_34 AC 131 ms
13,184 KB
testcase_35 AC 138 ms
13,032 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define chmin(x,y) (x) = min((x),(y))
#define chmax(x,y) (x) = max((x),(y))
using namespace std;
using ll = long long;
int main(){
  // input
  int H,W; cin >> H >> W;
  H-= 2;
  vector<vector<ll>> A(H,vector<ll>(W));
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      cin >> A[i][j];
  
  // solve: dp
  vector<vector<ll>> dp(W+1,vector<ll>(H,9e18));
  for (int j = 0; j < H; j++)
    dp[0][j] = 0;
  
  for (int i = 0; i < W; i++){
    for (int j = 0; j < H; j++){
      ll cost = A[j][i];
      if(cost == -1) continue;
      chmin(dp[i+1][j],dp[i][j]+cost);
      if(j > 0) chmin(dp[i+1][j],dp[i][j-1]+cost);
      if(j + 1 < H) chmin(dp[i+1][j],dp[i][j+1]+cost);
      
      // cout << i << " " << j << " " << dp[i+1][j] << endl;
    }
  }
  
  // output
  ll ans = 9e18;
  for (int j = 0; j < H; j++)    
    chmin(ans,dp[W][j]);
  
  cout << (ans < 9e18? ans : -1) << endl;
}
0