結果

問題 No.2095 High Rise
ユーザー yansi819yansi819
提出日時 2024-04-13 11:03:55
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 975 bytes
コンパイル時間 4,970 ms
コンパイル使用メモリ 255,040 KB
実行使用メモリ 11,716 KB
最終ジャッジ日時 2024-04-13 11:04:06
合計ジャッジ時間 10,557 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 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,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 AC 2 ms
6,944 KB
testcase_11 AC 2 ms
6,940 KB
testcase_12 AC 4 ms
6,944 KB
testcase_13 AC 3 ms
6,940 KB
testcase_14 AC 5 ms
6,948 KB
testcase_15 AC 3 ms
6,940 KB
testcase_16 AC 3 ms
6,940 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
権限があれば一括ダウンロードができます

ソースコード

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];
int 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] = 1e9;
  }
  for (int j = 0; j < M; j++) dp[0][j] = 0;
  for (int i = 0; i < N; i++) {
    int 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