結果

問題 No.2095 High Rise
ユーザー yansi819yansi819
提出日時 2024-04-13 11:06:06
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 446 ms / 2,000 ms
コード長 974 bytes
コンパイル時間 4,634 ms
コンパイル使用メモリ 256,084 KB
実行使用メモリ 15,572 KB
最終ジャッジ日時 2024-04-13 11:06:15
合計ジャッジ時間 8,769 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 3 ms
6,940 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 2 ms
6,940 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 3 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 5 ms
6,944 KB
testcase_15 AC 3 ms
6,944 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 AC 51 ms
8,736 KB
testcase_18 AC 35 ms
9,052 KB
testcase_19 AC 10 ms
6,944 KB
testcase_20 AC 54 ms
8,768 KB
testcase_21 AC 101 ms
8,968 KB
testcase_22 AC 429 ms
15,440 KB
testcase_23 AC 419 ms
15,572 KB
testcase_24 AC 446 ms
15,444 KB
testcase_25 AC 429 ms
15,448 KB
testcase_26 AC 422 ms
15,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using ld = long double;
using mint = modint998244353;

int N, M, A[1010][1010];
ll dp[1010][1010];

int main() {
  cin >> N >> M;
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) cin >> A[i][j];
  }
  if (N == 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i <= N; i++) {
    for (int j = 0; j < M; j++) dp[i][j] = 1e18;
  }
  for (int j = 0; j < M; j++) dp[0][j] = 0;
  for (int i = 0; i < N; i++) {
    ll m = *min_element(dp[i], dp[i] + M);
    for (int j = 0; j < M; j++) {
      if (dp[i][j] == m) {
        dp[i + 1][j] = m + A[i][j];
      } else {
        dp[i + 1][j] = min(m + A[i][j] + (i >= 1 ? A[i - 1][j]: 0), dp[i][j] + A[i][j]);
      }
    }
  }
  //for (int i = 0; i <= N; i++) for (int j = 0; j < M; j++) cout << dp[i][j] << " \n"[j == M - 1];
  cout << *min_element(dp[N], dp[N] + M) << endl;
  return 0;
}
0