結果

問題 No.2157 崖
ユーザー kotamanegikotamanegi
提出日時 2022-12-06 00:22:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2,441 ms / 6,000 ms
コード長 1,627 bytes
コンパイル時間 2,598 ms
コンパイル使用メモリ 165,900 KB
実行使用メモリ 35,468 KB
最終ジャッジ日時 2024-04-22 15:33:01
合計ジャッジ時間 25,238 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1 ms
5,376 KB
testcase_07 AC 1 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 1,848 ms
24,064 KB
testcase_14 AC 2,177 ms
32,612 KB
testcase_15 AC 1,836 ms
23,808 KB
testcase_16 AC 1,884 ms
24,028 KB
testcase_17 AC 1,861 ms
28,160 KB
testcase_18 AC 1,801 ms
27,632 KB
testcase_19 AC 2,319 ms
29,148 KB
testcase_20 AC 2,441 ms
35,456 KB
testcase_21 AC 2,441 ms
35,468 KB
testcase_22 AC 1,710 ms
26,508 KB
testcase_23 AC 2 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:1:17: warning: using directive refers to implicitly-defined namespace 'std'
    1 | using namespace std;
      |                 ^
1 warning generated.

ソースコード

diff #

using namespace std;
#include "bits/stdc++.h"

#define REP(a, b) for (long long a = 0; a < b; ++a)
#define ALL(a) begin(a), end(a)

#define ld long double
#define int long long
vector<vector<int>> inputs;
int n, m;
int can(int target)
{
  vector<vector<int>> nexts(n, vector<int>(m, 0));
  REP(i, m)
  {
    nexts[0][i] = 1;
  }
  for (int i = 1; i < n; ++i)
  {
    int l = 0;
    int r = 0;
    int cnts = 0;
    for (int j = 0; j < m; ++j)
    {
      while (r != m and inputs[i - 1][r] <= inputs[i][j])
      {
        cnts += nexts[i - 1][r];
        r++;
      }
      while (l != m and inputs[i - 1][l] + target + 1 <= inputs[i][j])
      {
        cnts -= nexts[i - 1][l];
        l++;
      }
      if (cnts != 0)
      {
        nexts[i][j] = 1;
      }
    }
  }
  REP(i, m)
  {
    if (nexts[n - 1][i])
      return 1;
  }
  return 0;
}
void solve()
{
  cin >> n >> m;
  REP(i, n)
  {
    vector<int> now;
    REP(q, m)
    {
      int x;
      cin >> x;
      now.push_back(x);
    }
    sort(ALL(now));
    inputs.push_back(now);
  }
  int bot = 1e18;
  int top = -1;
  while (bot - top > 1)
  {
    int mid = (bot + top) / 2;
    if (can(mid))
    {
      bot = mid;
    }
    else
    {
      top = mid;
    }
  }
  if (can(bot))
  {
    cout << bot << endl;
  }
  else
  {
    cout << -1 << endl;
  }
}

#undef int

int main()
{
  // Fasterize input/output script
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(100);

  int t = 1;
  // cin >> t; // comment out if solving multi testcase
  for (int testCase = 1; testCase <= t; ++testCase)
  {
    solve();
  }
  return 0;
}
0