結果

問題 No.2157 崖
ユーザー SSRSSSRS
提出日時 2022-12-09 21:54:51
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 1,743 ms / 6,000 ms
コード長 1,235 bytes
コンパイル時間 1,696 ms
コンパイル使用メモリ 176,688 KB
実行使用メモリ 27,668 KB
最終ジャッジ日時 2024-04-22 21:57:29
合計ジャッジ時間 17,101 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 2 ms
6,940 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 1 ms
6,944 KB
testcase_11 AC 2 ms
6,944 KB
testcase_12 AC 2 ms
6,940 KB
testcase_13 AC 1,362 ms
18,960 KB
testcase_14 AC 1,321 ms
25,576 KB
testcase_15 AC 1,459 ms
18,704 KB
testcase_16 AC 1,469 ms
18,892 KB
testcase_17 AC 1,104 ms
22,064 KB
testcase_18 AC 1,071 ms
21,576 KB
testcase_19 AC 1,743 ms
22,836 KB
testcase_20 AC 1,402 ms
27,668 KB
testcase_21 AC 1,419 ms
27,576 KB
testcase_22 AC 1,013 ms
20,968 KB
testcase_23 AC 1 ms
6,940 KB
testcase_24 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
int main(){
  int N, M;
  cin >> N >> M;
  vector<vector<int>> D(N, vector<int>(M));
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      cin >> D[i][j];
    }
  }
  vector<pair<int, int>> P(N * M);
  for (int i = 0; i < N; i++){
    for (int j = 0; j < M; j++){
      P[i * M + j] = make_pair(D[i][j], i);
    }
  }
  sort(P.begin(), P.end());
  int tv = INF, fv = -1;
  while (tv - fv > 1){
    int mid = (tv + fv) / 2;
    vector<bool> dp(N * M, false);
    vector<int> S(N, 0);
    int p = 0;
    for (int i = 0; i < N * M; i++){
      while (P[i].first - P[p].first > mid){
        if (dp[p]){
          S[P[p].second]--;
        }
        p++;
      }
      if (P[i].second == 0){
        dp[i] = true;
      } else {
        if (S[P[i].second - 1] > 0){
          dp[i] = true;
        }
      }
      if (dp[i]){
        S[P[i].second]++;
      }
    }
    bool ok = false;
    for (int i = 0; i < N * M; i++){
      if (P[i].second == N - 1 && dp[i]){
        ok = true;
      }
    }
    if (ok){
      tv = mid;
    } else {
      fv = mid;
    }
  }
  if (tv == INF){
    cout << -1 << endl;
  } else {
    cout << tv << endl;
  }
}
0