結果

問題 No.2095 High Rise
ユーザー 👑 chro_96chro_96
提出日時 2022-10-07 22:30:50
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 957 bytes
コンパイル時間 1,408 ms
コンパイル使用メモリ 29,320 KB
実行使用メモリ 17,556 KB
最終ジャッジ日時 2023-09-03 13:43:30
合計ジャッジ時間 3,605 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 5 ms
17,556 KB
testcase_01 AC 5 ms
17,544 KB
testcase_02 AC 6 ms
17,348 KB
testcase_03 AC 6 ms
17,348 KB
testcase_04 AC 5 ms
17,512 KB
testcase_05 AC 6 ms
17,452 KB
testcase_06 AC 6 ms
17,544 KB
testcase_07 AC 6 ms
17,552 KB
testcase_08 AC 5 ms
17,352 KB
testcase_09 AC 5 ms
17,408 KB
testcase_10 AC 5 ms
17,472 KB
testcase_11 AC 5 ms
17,472 KB
testcase_12 AC 7 ms
17,468 KB
testcase_13 AC 5 ms
17,352 KB
testcase_14 AC 6 ms
17,540 KB
testcase_15 AC 6 ms
17,460 KB
testcase_16 AC 6 ms
17,544 KB
testcase_17 AC 21 ms
17,448 KB
testcase_18 AC 15 ms
17,480 KB
testcase_19 AC 9 ms
17,476 KB
testcase_20 AC 22 ms
17,408 KB
testcase_21 AC 37 ms
17,548 KB
testcase_22 AC 140 ms
17,448 KB
testcase_23 AC 141 ms
17,548 KB
testcase_24 AC 140 ms
17,464 KB
testcase_25 AC 140 ms
17,348 KB
testcase_26 AC 140 ms
17,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int main () {
  int n = 0;
  int m = 0;
  long long a[1000][1000] = {};

  int res = 0;
  
  long long dp[1000][1000] = {};
  long long ans = 0LL;
  
  res = scanf("%d", &n);
  res = scanf("%d", &m);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      res = scanf("%lld", a[i]+j);
    }
  }
  
  if (n <= 1) {
    printf("0\n");
    return 0;
  }
  
  for (int i = 0; i < m; i++) {
    dp[0][i] = a[0][i];
  }
  
  for (int i = 1; i < n; i++) {
    long long min = dp[i-1][0];
    for (int j = 1; j < m; j++) {
      if (dp[i-1][j] < min) {
        min = dp[i-1][j];
      }
    }
    for (int j = 0; j < m; j++) {
      dp[i][j] = dp[i-1][j]+a[i][j];
      if (min+a[i][j]+a[i-1][j] < dp[i][j]) {
        dp[i][j] = min+a[i][j]+a[i-1][j];
      }
    }
  }
  
  ans = dp[n-1][0];
  for (int i = 1; i < m; i++) {
    if (dp[n-1][i] < ans) {
      ans = dp[n-1][i];
    }
  }
  
  printf("%lld\n", ans);
  return 0;
}
0