結果

問題 No.2328 Build Walls
ユーザー keisuke6keisuke6
提出日時 2023-05-28 14:15:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 715 bytes
コンパイル時間 2,233 ms
コンパイル使用メモリ 203,932 KB
実行使用メモリ 13,328 KB
最終ジャッジ日時 2023-08-27 09:23:01
合計ジャッジ時間 6,079 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,380 KB
testcase_12 AC 2 ms
4,384 KB
testcase_13 AC 68 ms
8,372 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 10 ms
4,380 KB
testcase_20 WA -
testcase_21 AC 61 ms
8,184 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 127 ms
13,024 KB
testcase_29 WA -
testcase_30 AC 134 ms
13,096 KB
testcase_31 AC 133 ms
13,084 KB
testcase_32 WA -
testcase_33 AC 144 ms
13,052 KB
testcase_34 AC 136 ms
13,092 KB
testcase_35 AC 144 ms
13,048 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int H,W;
  cin>>H>>W;
  H -= 2;
  vector<vector<int>> A(H,vector<int>(W));
  for(int i=0;i<H;i++)for(int j=0;j<W;j++){
  	cin>>A[i][j];
  	if(A[i][j] == -1) A[i][j] = 1e18;
  } 
  vector<vector<int>> dp(H,vector<int>(W,1e18));
  for(int i=0;i<H;i++) dp[i][0] = A[i][0];
  for(int i=0;i<W-1;i++){
  	for(int j=0;j<H;j++){
  		dp[j][i+1] = min(dp[j][i+1],dp[j][i]+A[j][i+1]);
  		if(j != H-1) dp[j+1][i+1] = min(dp[j+1][i+1],dp[j][i]+A[j+1][i+1]);
  		if(j) dp[j-1][i+1] = min(dp[j-1][i+1],dp[j][i]+A[j-1][i+1]);
  	}
  }
  int ans = 1e18;
  for(int i=0;i<H;i++) ans = min(ans,dp[i][W-1]);
  cout<<(ans == 1e18 ? -1 : ans)<<endl;
}
0