結果

問題 No.2157 崖
ユーザー 👑 chro_96chro_96
提出日時 2022-12-09 22:37:29
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 1,665 ms / 6,000 ms
コード長 1,417 bytes
コンパイル時間 502 ms
コンパイル使用メモリ 32,512 KB
実行使用メモリ 37,120 KB
最終ジャッジ日時 2024-04-22 22:41:06
合計ジャッジ時間 16,863 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 9 ms
36,992 KB
testcase_01 AC 9 ms
36,828 KB
testcase_02 AC 10 ms
36,864 KB
testcase_03 AC 9 ms
36,736 KB
testcase_04 AC 9 ms
36,864 KB
testcase_05 AC 10 ms
36,712 KB
testcase_06 AC 10 ms
36,736 KB
testcase_07 AC 10 ms
36,828 KB
testcase_08 AC 9 ms
36,948 KB
testcase_09 AC 10 ms
36,864 KB
testcase_10 AC 9 ms
36,992 KB
testcase_11 AC 10 ms
36,836 KB
testcase_12 AC 14 ms
36,896 KB
testcase_13 AC 1,352 ms
36,832 KB
testcase_14 AC 1,503 ms
36,864 KB
testcase_15 AC 1,345 ms
36,988 KB
testcase_16 AC 1,400 ms
36,864 KB
testcase_17 AC 1,251 ms
37,120 KB
testcase_18 AC 1,188 ms
36,864 KB
testcase_19 AC 1,665 ms
36,992 KB
testcase_20 AC 1,586 ms
36,864 KB
testcase_21 AC 1,579 ms
36,864 KB
testcase_22 AC 1,161 ms
36,864 KB
testcase_23 AC 10 ms
36,972 KB
testcase_24 AC 11 ms
36,864 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <stdlib.h>

#define INF 1000000000000000LL

int cmp_ll (const void *ap, const void *bp) {
  long long a = *(long long *)ap;
  long long b = *(long long *)bp;
  
  if (a < b) {
    return -1;
  }
  
  if (a > b) {
    return 1;
  }
  
  return 0;
}

int main () {
  int n = 0;
  int m = 0;
  long long d[1500][1500] = {};
  
  int res = 0;
  
  long long dp[1500][1501] = {};
  long long ans[2] = { -1LL, INF };
  
  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", d[i]+j);
    }
    qsort(d[i], m, sizeof(long long), cmp_ll);
  }
  
  while (ans[1]-ans[0] > 1LL) {
    long long nxt = (ans[0]+ans[1])/2LL;
    for (int j = 0; j <= m; j++) {
      dp[0][j] = j;
    }
    for (int i = 1; i < n; i++) {
      int idx1 = 0;
      int idx2 = 0;
      for (int j = 0; j < m; j++) {
        while (idx1 < m && d[i][j]-nxt > d[i-1][idx1]) {
          idx1++;
        }
        while (idx2 < m && d[i][j] >= d[i-1][idx2]) {
          idx2++;
        }
        if (dp[i-1][idx2]-dp[i-1][idx1] > 0) {
          dp[i][j+1] = dp[i][j]+1;
        } else {
          dp[i][j+1] = dp[i][j];
        }
      }
    }
    if (dp[n-1][m] > 0) {
      ans[1] = nxt;
    } else {
      ans[0] = nxt;
    }
  }
  
  if (ans[1] >= INF) {
    printf("-1\n");
  } else {
    printf("%lld\n", ans[1]);
  }
  
  return 0;
}
0