結果

問題 No.2667 Constrained Permutation
ユーザー 👑 emthrmemthrm
提出日時 2024-03-08 21:36:10
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,812 bytes
コンパイル時間 3,361 ms
コンパイル使用メモリ 266,048 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-08 21:36:28
合計ジャッジ時間 9,651 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 100 ms
6,676 KB
testcase_13 AC 4 ms
6,676 KB
testcase_14 AC 298 ms
6,676 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 15 ms
6,676 KB
testcase_18 AC 318 ms
6,676 KB
testcase_19 AC 276 ms
6,676 KB
testcase_20 AC 314 ms
6,676 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 149 ms
6,676 KB
testcase_25 AC 291 ms
6,676 KB
testcase_26 AC 355 ms
6,676 KB
testcase_27 AC 324 ms
6,676 KB
testcase_28 AC 51 ms
6,676 KB
testcase_29 AC 49 ms
6,676 KB
testcase_30 AC 54 ms
6,676 KB
testcase_31 AC 33 ms
6,676 KB
testcase_32 AC 8 ms
6,676 KB
testcase_33 AC 77 ms
6,676 KB
testcase_34 AC 41 ms
6,676 KB
testcase_35 AC 50 ms
6,676 KB
testcase_36 AC 49 ms
6,676 KB
testcase_37 AC 51 ms
6,676 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 AC 41 ms
6,676 KB
testcase_41 AC 64 ms
6,676 KB
testcase_42 AC 177 ms
6,676 KB
testcase_43 AC 240 ms
6,676 KB
testcase_44 WA -
testcase_45 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
using ll = long long;
constexpr int INF = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr double EPS = 1e-8;
constexpr int MOD = 998244353;
// constexpr int MOD = 1000000007;
constexpr int DY4[]{1, 0, -1, 0}, DX4[]{0, -1, 0, 1};
constexpr int DY8[]{1, 1, 0, -1, -1, -1, 0, 1};
constexpr int DX8[]{0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U>
inline bool chmax(T& a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U>
inline bool chmin(T& a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);
  }
} iosetup;

int main() {
  int n; cin >> n;
  vector<pair<int, int>> lr(n); for (auto& [l, r] : lr) cin >> l >> r;
  ranges::sort(lr);
  for (int i = n - 1; i >= 0; --i) {
    lr[i].second -= lr.front().first;
    lr[i].first -= lr.front().first;
  }
  int d = 0;
  REP(i, n) chmax(d, lr[i].first - i);
  for (auto& [l, r] : lr) {
    l = max(0, l - d);
    r -= d;
    if (r < l) {
      cout << 0 << '\n';
      return 0;
    }
  }
  ranges::sort(lr);
  int lb = -1, ub = ranges::min(lr, {}, [](const auto& p) -> int { return p.second; }).second + 1;
  while (ub - lb > 1) {
    const int k = midpoint(lb, ub);
    bool is_valid = true;
    int id = 0;
    priority_queue<int, vector<int>, greater<int>> que;
    REP(i, n) {
      while (id < n && lr[id].first <= i) que.emplace(lr[id++].second);
      if (que.empty() || que.top() < i) {
        is_valid = false;
        break;
      }
      que.pop();
    }
    (is_valid ? lb : ub) = k;
  }
  cout << lb + 1 << '\n';
  return 0;
}
0