結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,036 KB
testcase_01 AC 2 ms
4,992 KB
testcase_02 AC 2 ms
5,000 KB
testcase_03 AC 2 ms
4,988 KB
testcase_04 AC 2 ms
5,076 KB
testcase_05 AC 2 ms
4,992 KB
testcase_06 AC 1 ms
5,008 KB
testcase_07 AC 2 ms
5,000 KB
testcase_08 AC 2 ms
5,068 KB
testcase_09 AC 1 ms
5,020 KB
testcase_10 AC 2 ms
5,056 KB
testcase_11 AC 2 ms
5,056 KB
testcase_12 AC 2 ms
5,020 KB
testcase_13 AC 34 ms
7,180 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 6 ms
5,556 KB
testcase_20 WA -
testcase_21 AC 28 ms
7,524 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,936 KB
testcase_29 WA -
testcase_30 AC 61 ms
8,000 KB
testcase_31 AC 60 ms
7,940 KB
testcase_32 WA -
testcase_33 AC 59 ms
7,972 KB
testcase_34 AC 62 ms
7,940 KB
testcase_35 AC 62 ms
7,892 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;
	int d = min(min(d0, d1), d2);
	dp[i][j] = (d < INF) ? d + as[i][j] : INF;
      }
      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