結果

問題 No.2543 Many Meetings
ユーザー 👑 emthrmemthrm
提出日時 2023-11-24 22:33:38
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,013 bytes
コンパイル時間 3,613 ms
コンパイル使用メモリ 271,220 KB
実行使用メモリ 44,048 KB
最終ジャッジ日時 2023-11-24 22:33:50
合計ジャッジ時間 11,147 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 302 ms
44,048 KB
testcase_04 AC 297 ms
44,048 KB
testcase_05 AC 301 ms
44,048 KB
testcase_06 AC 358 ms
44,048 KB
testcase_07 AC 301 ms
44,048 KB
testcase_08 AC 296 ms
44,048 KB
testcase_09 AC 297 ms
44,048 KB
testcase_10 AC 322 ms
44,048 KB
testcase_11 AC 318 ms
44,048 KB
testcase_12 AC 314 ms
44,048 KB
testcase_13 AC 264 ms
35,460 KB
testcase_14 AC 158 ms
21,556 KB
testcase_15 AC 145 ms
21,248 KB
testcase_16 AC 218 ms
30,040 KB
testcase_17 AC 258 ms
33,872 KB
testcase_18 AC 240 ms
37,632 KB
testcase_19 WA -
testcase_20 AC 243 ms
34,872 KB
testcase_21 AC 296 ms
40,128 KB
testcase_22 AC 220 ms
33,968 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 AC 16 ms
6,676 KB
testcase_30 WA -
testcase_31 AC 14 ms
6,676 KB
testcase_32 AC 42 ms
6,676 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 1 ms
6,676 KB
testcase_37 AC 1 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 2 ms
6,676 KB
testcase_40 AC 2 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

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() {
  constexpr int L = 18;
  int n, k; cin >> n >> k;
  map<int, int> rl;
  while (n--) {
    int l, r; cin >> l >> r; --l; --r;
    if (const auto it = rl.find(l); it == rl.end()) {
      rl[r] = l;
    } else {
      chmax(rl[r], l);
    }
  }
  vector<int> tm;
  tm.reserve(rl.size() * 2);
  for (const auto& [r, l] : rl) {
    tm.emplace_back(l);
    tm.emplace_back(r);
  }
  ranges::sort(tm);
  tm.erase(unique(tm.begin(), tm.end()), tm.end());
  const int m = tm.size();
  vector dp(L, vector(m, m));
  vector<int> r_min(m);
  for (const auto& [r, l] : rl) {
    const int l_ind = distance(tm.begin(), ranges::lower_bound(tm, l));
    const int r_ind = distance(tm.begin(), ranges::lower_bound(tm, r));
    chmin(dp[0][l_ind], r_ind);
  }
  for (int i = m - 2; i >= 0; --i) chmin(dp[0][i], dp[0][i + 1]);
  REP(i, L - 1) REP(j, m) {
    if (dp[i][j] < m) chmin(dp[i + 1][j], dp[i][dp[i][j]]);
  }
  int ans = INF;
  REP(i, m) {
    int cur = i;
    for (int bit = 0, j = k; j > 0 && cur < m; ++bit, j /= 2) {
      if (j & 1) cur = dp[bit][cur];
    }
    if (cur < m) chmin(ans, tm[cur] - tm[i]);
  }
  cout << (ans == INF ? -1 : ans) << '\n';
  return 0;
}
0