結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 1 ms
4,376 KB
testcase_13 AC 71 ms
8,360 KB
testcase_14 WA -
testcase_15 AC 37 ms
5,560 KB
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,792 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 121 ms
12,960 KB
testcase_29 WA -
testcase_30 AC 132 ms
12,952 KB
testcase_31 AC 130 ms
13,308 KB
testcase_32 WA -
testcase_33 AC 288 ms
13,188 KB
testcase_34 AC 134 ms
13,016 KB
testcase_35 AC 145 ms
13,312 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define chmin(x,y) (x) = min((x),(y))
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;
      
      chmin(dp[i+1][j],dp[i][j]+cost);
      
      ll cos_u = cost;
      for (int k = j - 1; k >= 0; k--){
        chmin(dp[i+1][j],dp[i][k]+cos_u);
        if(A[i][k] > 0) cos_u += A[i][k];
        else break;
      }
      
      ll cos_d = cost;
      for (int k = j + 1; k < H; k++){
        chmin(dp[i+1][j],dp[i][k]+cos_d);
        if(A[i][k] > 0) cos_d += A[i][k];
        else break;
      }
    }
  }
  
  // output
  ll ans = 9e18;
  for (int j = 0; j < H; j++)    
    ans = min(ans,dp[W][j]);
  
  cout << (ans < 9e18? ans : -1) << endl;
}
0