結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 1 ms
4,376 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 70 ms
8,272 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 11 ms
4,376 KB
testcase_20 WA -
testcase_21 AC 60 ms
7,836 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 123 ms
12,996 KB
testcase_29 WA -
testcase_30 AC 132 ms
12,956 KB
testcase_31 AC 129 ms
13,136 KB
testcase_32 WA -
testcase_33 AC 138 ms
13,116 KB
testcase_34 AC 133 ms
13,076 KB
testcase_35 AC 138 ms
13,120 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  // input
  int H,W; cin >> H >> W;
  H -= 2;
  vector<vector<ll>> A(W,vector<ll>(H));
  for (int i = 0; i < H; i++)
    for (int j = 0; j < W; j++)
      cin >> A[j][i];
  
  // 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[i][j];
      if(cost == -1) continue;
      
      dp[i+1][j] = min(dp[i+1][j],dp[i][j]+cost);
      if(j - 1 >= 0)
        dp[i+1][j] = min(dp[i+1][j],dp[i][j-1]+cost);
      if(j + 1 < H)
        dp[i+1][j] = min(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++)    
    ans = min(ans,dp[W][j]);
  
  cout << (ans < 9e18? ans : -1) << endl;
}
0