結果

問題 No.2328 Build Walls
ユーザー tnakao0123tnakao0123
提出日時 2023-06-26 17:41:16
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,008 bytes
コンパイル時間 238 ms
コンパイル使用メモリ 42,216 KB
実行使用メモリ 8,044 KB
最終ジャッジ日時 2023-09-16 11:50:59
合計ジャッジ時間 2,944 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,032 KB
testcase_01 AC 2 ms
5,084 KB
testcase_02 AC 2 ms
4,956 KB
testcase_03 AC 2 ms
4,980 KB
testcase_04 AC 2 ms
5,088 KB
testcase_05 AC 2 ms
5,040 KB
testcase_06 AC 2 ms
5,024 KB
testcase_07 AC 2 ms
5,036 KB
testcase_08 AC 2 ms
5,088 KB
testcase_09 AC 2 ms
5,004 KB
testcase_10 AC 1 ms
5,036 KB
testcase_11 AC 1 ms
4,984 KB
testcase_12 AC 2 ms
4,988 KB
testcase_13 AC 34 ms
7,088 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 6 ms
5,544 KB
testcase_20 WA -
testcase_21 AC 28 ms
7,516 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 52 ms
7,968 KB
testcase_29 WA -
testcase_30 AC 62 ms
7,956 KB
testcase_31 AC 60 ms
7,988 KB
testcase_32 WA -
testcase_33 AC 58 ms
7,968 KB
testcase_34 AC 62 ms
7,940 KB
testcase_35 AC 62 ms
7,980 KB
testcase_36 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2328.cc:  No.2328 Build Walls - yukicoder
 */

#include<cstdio>
#include<algorithm>
 
using namespace std;

/* constant */

const int MAX_H = 800;
const int MAX_W = 800;
const int INF = 1 << 30;

/* typedef */

/* global variables */

int as[MAX_H][MAX_W], dp[MAX_H][MAX_W];

/* subroutines */

/* main */

int main() {
  int h, w;
  scanf("%d%d", &h, &w);
  h -= 2;

  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) scanf("%d", as[i] + j);
  
  for (int i = 0; i < h; i++)
    dp[i][0] = (as[i][0] >= 0) ? as[i][0] : INF;
  
  for (int j = 1; j < w; j++)
    for (int i = 0; i < h; i++) {
      if (as[i][j] >= 0) {
	int d0 = (i > 0) ? dp[i - 1][j - 1] : INF;
	int d1 = dp[i][j - 1];
	int d2 = (i + 1 < h) ? dp[i + 1][j - 1] : INF;
	dp[i][j] = min(min(d0, d1), d2) + as[i][j];
      }
      else
	dp[i][j] = INF;
    }

  int mind = INF;
  for (int i = 0; i < h; i++)
    mind = min(mind, dp[i][w - 1]);

  printf("%d\n", (mind < INF) ? mind : -1);
  return 0;
}
0