結果

問題 No.2095 High Rise
ユーザー SSRSSSRS
提出日時 2022-10-07 21:31:40
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 371 ms / 2,000 ms
コード長 935 bytes
コンパイル時間 1,836 ms
コンパイル使用メモリ 174,160 KB
実行使用メモリ 15,144 KB
最終ジャッジ日時 2023-09-03 00:26:12
合計ジャッジ時間 5,513 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 3 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,384 KB
testcase_17 AC 43 ms
4,652 KB
testcase_18 AC 29 ms
4,384 KB
testcase_19 AC 8 ms
4,380 KB
testcase_20 AC 47 ms
4,452 KB
testcase_21 AC 88 ms
5,760 KB
testcase_22 AC 370 ms
14,852 KB
testcase_23 AC 371 ms
15,144 KB
testcase_24 AC 370 ms
14,884 KB
testcase_25 AC 366 ms
14,848 KB
testcase_26 AC 369 ms
14,832 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const long long INF = 1000000000000000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> A(N, vector<int>(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;
  } else {
    vector<vector<long long>> dp(N, vector<long long>(M, INF));
    for (int i = 0; i < M; i++){
      dp[0][i] = A[0][i];
    }
    for (int i = 0; i < N - 1; i++){
      for (int j = 0; j < M; j++){
        dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + A[i + 1][j]);
      }
      long long mn = INF;
      for (int j = 0; j < M; j++){
        mn = min(mn, dp[i + 1][j]);
      }
      for (int j = 0; j < M; j++){
        dp[i + 1][j] = min(dp[i + 1][j], mn + A[i + 1][j]);
      }
    }
    long long ans = INF;
    for (int i = 0; i < M; i++){
      ans = min(ans, dp[N - 1][i]);
    }
    cout << ans << endl;
  }
}
0