結果

問題 No.2095 High Rise
ユーザー tnakao0123tnakao0123
提出日時 2022-10-08 01:10:38
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 135 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 267 ms
コンパイル使用メモリ 41,788 KB
実行使用メモリ 14,736 KB
最終ジャッジ日時 2023-09-03 18:11:02
合計ジャッジ時間 4,490 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,996 KB
testcase_01 AC 2 ms
5,016 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,936 KB
testcase_04 AC 2 ms
4,996 KB
testcase_05 AC 2 ms
5,004 KB
testcase_06 AC 2 ms
5,040 KB
testcase_07 AC 2 ms
5,064 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,980 KB
testcase_11 AC 2 ms
5,032 KB
testcase_12 AC 2 ms
5,228 KB
testcase_13 AC 2 ms
5,300 KB
testcase_14 AC 3 ms
5,360 KB
testcase_15 AC 2 ms
5,172 KB
testcase_16 AC 2 ms
5,164 KB
testcase_17 AC 18 ms
10,900 KB
testcase_18 AC 14 ms
10,644 KB
testcase_19 AC 5 ms
7,804 KB
testcase_20 AC 19 ms
8,576 KB
testcase_21 AC 35 ms
11,200 KB
testcase_22 AC 135 ms
14,684 KB
testcase_23 AC 135 ms
14,680 KB
testcase_24 AC 134 ms
14,712 KB
testcase_25 AC 134 ms
14,736 KB
testcase_26 AC 134 ms
14,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* -*- coding: utf-8 -*-
 *
 * 2095.cc:  No.2095 High Rise - yukicoder
 */

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

/* constant */

const int MAX_N = 1000;
const int MAX_M = 1000;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N][MAX_M];
ll dp[MAX_N + 1][MAX_N];

/* subroutines */

inline void setmin(ll &a, ll b) { if (a > b) a = b; }

/* main */

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n == 1) { puts("0"); return 0; }

  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++) scanf("%d", as[i] + j);

  ll mind = 0;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      dp[i + 1][j] = dp[i][j] + as[i][j];
      if (i > 0)
	setmin(dp[i + 1][j], mind + as[i - 1][j] + as[i][j]);
    }
    mind = *min_element(dp[i + 1], dp[i + 1] + m);
  }

  printf("%lld\n", mind);

  return 0;
}
0