結果

問題 No.2157 崖
ユーザー kotamanegikotamanegi
提出日時 2022-12-06 00:20:35
言語 C++17(clang)
(17.0.6 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,626 bytes
コンパイル時間 3,546 ms
コンパイル使用メモリ 166,552 KB
実行使用メモリ 35,584 KB
最終ジャッジ日時 2024-04-22 15:32:02
合計ジャッジ時間 29,983 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 1 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2,075 ms
24,192 KB
testcase_14 AC 2,424 ms
32,868 KB
testcase_15 AC 2,042 ms
23,808 KB
testcase_16 AC 2,074 ms
24,036 KB
testcase_17 AC 2,071 ms
28,288 KB
testcase_18 AC 2,013 ms
27,624 KB
testcase_19 AC 2,599 ms
29,148 KB
testcase_20 AC 2,673 ms
35,584 KB
testcase_21 AC 2,669 ms
35,216 KB
testcase_22 AC 1,932 ms
26,640 KB
testcase_23 AC 1 ms
5,376 KB
testcase_24 AC 7 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 = 0;
  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