結果

問題 No.2157 崖
ユーザー kotamanegikotamanegi
提出日時 2022-12-06 00:22:05
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
AC  
実行時間 2,619 ms / 6,000 ms
コード長 1,627 bytes
コンパイル時間 4,369 ms
コンパイル使用メモリ 134,068 KB
実行使用メモリ 35,344 KB
最終ジャッジ日時 2023-08-04 17:28:11
合計ジャッジ時間 27,168 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,384 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,384 KB
testcase_12 AC 1 ms
4,384 KB
testcase_13 AC 2,026 ms
24,044 KB
testcase_14 AC 2,354 ms
32,632 KB
testcase_15 AC 1,977 ms
23,644 KB
testcase_16 AC 2,020 ms
23,800 KB
testcase_17 AC 1,997 ms
28,180 KB
testcase_18 AC 1,941 ms
27,372 KB
testcase_19 AC 2,475 ms
29,052 KB
testcase_20 AC 2,617 ms
35,300 KB
testcase_21 AC 2,619 ms
35,344 KB
testcase_22 AC 1,898 ms
26,428 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 7 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:1:17: warning: using directive refers to implicitly-defined namespace 'std'
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