結果

問題 No.2543 Many Meetings
ユーザー MisukiMisuki
提出日時 2023-12-31 17:39:32
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 2,924 bytes
コンパイル時間 3,541 ms
コンパイル使用メモリ 222,308 KB
実行使用メモリ 40,756 KB
最終ジャッジ日時 2023-12-31 17:39:41
合計ジャッジ時間 8,809 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 114 ms
40,756 KB
testcase_04 AC 108 ms
40,756 KB
testcase_05 AC 113 ms
40,756 KB
testcase_06 AC 109 ms
40,756 KB
testcase_07 AC 108 ms
40,756 KB
testcase_08 AC 111 ms
40,756 KB
testcase_09 AC 111 ms
40,756 KB
testcase_10 AC 111 ms
40,756 KB
testcase_11 AC 113 ms
40,756 KB
testcase_12 AC 113 ms
40,756 KB
testcase_13 AC 84 ms
32,948 KB
testcase_14 AC 48 ms
20,096 KB
testcase_15 AC 47 ms
19,768 KB
testcase_16 AC 71 ms
27,776 KB
testcase_17 AC 81 ms
31,500 KB
testcase_18 AC 83 ms
34,956 KB
testcase_19 AC 76 ms
32,080 KB
testcase_20 AC 77 ms
32,280 KB
testcase_21 AC 91 ms
37,136 KB
testcase_22 AC 75 ms
31,516 KB
testcase_23 AC 2 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 2 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 2 ms
6,676 KB
testcase_28 AC 72 ms
30,820 KB
testcase_29 AC 27 ms
12,544 KB
testcase_30 AC 26 ms
12,672 KB
testcase_31 AC 22 ms
11,136 KB
testcase_32 AC 68 ms
28,928 KB
testcase_33 AC 2 ms
6,676 KB
testcase_34 AC 2 ms
6,676 KB
testcase_35 AC 1 ms
6,676 KB
testcase_36 AC 2 ms
6,676 KB
testcase_37 AC 2 ms
6,676 KB
testcase_38 AC 2 ms
6,676 KB
testcase_39 AC 1 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 #

#pragma GCC optimize("O2")
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>

#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)

namespace R = std::ranges;
namespace V = std::views;

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = tuple<int, int, int>;
using ldb = long double;
//#define double ldb

template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
  return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
  for(const T &X : arr)
    os << X << ' ';
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
  for(const T &X : vec)
    os << X << ' ';
  return os;
}


signed main() {
  ios::sync_with_stdio(false), cin.tie(NULL);

  int n, k; cin >> n >> k;
  vector<array<int, 2>> seg(n);
  for(auto &[l, r] : seg)
    cin >> l >> r;

  sort(seg.begin(), seg.end(), [](array<int, 2> l, array<int, 2> r) { return l[1] > r[1]; });
  vector<array<int, 3>> cand(n);
  for(int i = 0; i < n; i++)
    cand[i] = {seg[i][0], seg[i][1], i};
  R::sort(cand);

  vector jp(18, vector<int>(n, -1));
  int mnR = INT_MAX, id = -1;
  for(int i = 0; i < n; i++) {
    auto [l, r] = seg[i];
    while(!cand.empty() and cand.back()[0] >= r) {
      auto [lp, rp, j] = cand.back();
      if (rp < mnR)
        mnR = rp, id = j;
      cand.pop_back();
    }
    jp[0][i] = id;
  }

  for(int i = 1; i < 18; i++)
    for(int j = 0; j < n; j++)
      if (jp[i - 1][j] != -1)
        jp[i][j] = jp[i - 1][jp[i - 1][j]];

  int ans = INT_MAX;
  for(int i = 0; i < n; i++) {
    int j = i;
    for(int bit = 0; bit < 18; bit++)
      if (j != -1 and ((k - 1) >> bit & 1))
        j = jp[bit][j];
    if (j != -1)
      ans = min(ans, seg[j][1] - seg[i][0]);
  }

  cout << (ans == INT_MAX ? -1 : ans) << '\n';

  return 0;
}
0