結果

問題 No.2543 Many Meetings
ユーザー maeshunmaeshun
提出日時 2023-11-24 22:46:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 680 ms / 2,000 ms
コード長 2,472 bytes
コンパイル時間 4,996 ms
コンパイル使用メモリ 271,876 KB
実行使用メモリ 60,544 KB
最終ジャッジ日時 2023-11-24 22:46:34
合計ジャッジ時間 18,200 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 647 ms
60,544 KB
testcase_04 AC 651 ms
60,544 KB
testcase_05 AC 680 ms
60,544 KB
testcase_06 AC 667 ms
60,544 KB
testcase_07 AC 627 ms
60,544 KB
testcase_08 AC 646 ms
60,544 KB
testcase_09 AC 616 ms
60,544 KB
testcase_10 AC 631 ms
60,544 KB
testcase_11 AC 608 ms
60,544 KB
testcase_12 AC 618 ms
60,544 KB
testcase_13 AC 481 ms
49,392 KB
testcase_14 AC 257 ms
29,120 KB
testcase_15 AC 288 ms
28,712 KB
testcase_16 AC 426 ms
40,136 KB
testcase_17 AC 507 ms
47,352 KB
testcase_18 AC 590 ms
52,312 KB
testcase_19 AC 549 ms
48,304 KB
testcase_20 AC 521 ms
48,576 KB
testcase_21 AC 585 ms
55,376 KB
testcase_22 AC 490 ms
47,352 KB
testcase_23 AC 3 ms
6,676 KB
testcase_24 AC 2 ms
6,676 KB
testcase_25 AC 3 ms
6,676 KB
testcase_26 AC 2 ms
6,676 KB
testcase_27 AC 3 ms
6,676 KB
testcase_28 AC 201 ms
6,728 KB
testcase_29 AC 70 ms
6,676 KB
testcase_30 AC 70 ms
6,676 KB
testcase_31 AC 59 ms
6,676 KB
testcase_32 AC 188 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 2 ms
6,676 KB
testcase_37 AC 2 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;
#include <atcoder/all>
using namespace atcoder;
#define rep(i, n) for(int i=0;i<(n);++i)
#define rep1(i, n) for(int i=1;i<=(n);i++)
#define ll long long
using mint = modint998244353;
using P = pair<ll,ll>;
using lb = long double;
using T = tuple<ll, ll, ll>;
#ifdef LOCAL
#  include <debug_print.hpp>
#  define dbg(...) debug_print::multi_print(#__VA_ARGS__, __VA_ARGS__)
#else
#  define dbg(...) (static_cast<void>(0))
#endif

// Coodinate Compression
// https://youtu.be/fR3W5IcBGLQ?t=8550
template<typename T=int>
struct CC {
  bool initialized;
  vector<T> xs;
  CC(): initialized(false) {}
  void add(T x) { xs.push_back(x);}
  void init() {
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(),xs.end()),xs.end());
    initialized = true;
  }
  int operator()(T x) {
    if (!initialized) init();
    return upper_bound(xs.begin(), xs.end(), x) - xs.begin() - 1;
  }
  T operator[](int i) {
    if (!initialized) init();
    return xs[i];
  }
  int size() {
    if (!initialized) init();
    return xs.size();
  }
};

int op(int a, int b) {
    return min(a,b);
}

int e(){
    return 1e9;
}

int main()
{
    int n, k;
    cin >> n >> k;
    vector<pair<int,int>> l(n);
    rep(i,n) cin >> l[i].first >> l[i].second;
    CC cc;
    rep(i,n) {
        cc.add(l[i].first);
        cc.add(l[i].second);
    }
    int m = cc.size();
    segtree<int, op, e> seg(m);
    rep(i,n){
        seg.set(cc(l[i].first), min(seg.get(cc(l[i].first)), cc(l[i].second)));
    }
    vector<vector<int>> dp(31, vector<int>(m, -1));
    rep(i,n){
        dp[0][cc(l[i].first)] = seg.prod(cc(l[i].first), m);
        if(dp[0][cc(l[i].second)]==1e9) dp[0][cc(l[i].second)] = -1;
        dp[0][cc(l[i].second)] = seg.prod(cc(l[i].second), m);
        if(dp[0][cc(l[i].second)]==1e9) dp[0][cc(l[i].second)] = -1;
    }
    dbg(dp);
    rep(k,30){
        rep(j,m){
            if(dp[k][j]==-1) continue;
            dp[k+1][j] = dp[k][dp[k][j]];
        }
    }
    int ans = 2e9;
    dbg(dp);
    rep(i,n){
        int now = cc(l[i].first);
        dbg(now);
        dbg(k);
        rep(j,30){
            if(k>>j&1) {
                if(now==-1) continue;
                now = dp[j][now];
                dbg(now);
                dbg(j);
            }
        }
        dbg(1,now);
        if(now==-1) continue;
        ans = min(ans, cc[now]-l[i].first);
    }
    if(ans==2e9) ans = -1;
    cout << ans << endl;
    return 0;
}
0