結果

問題 No.2543 Many Meetings
ユーザー 👑 NachiaNachia
提出日時 2023-11-16 01:02:35
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,503 bytes
コンパイル時間 871 ms
コンパイル使用メモリ 87,092 KB
実行使用メモリ 7,316 KB
最終ジャッジ日時 2023-11-16 01:02:41
合計ジャッジ時間 4,479 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 88 ms
7,316 KB
testcase_04 AC 86 ms
7,316 KB
testcase_05 AC 90 ms
7,316 KB
testcase_06 AC 87 ms
7,316 KB
testcase_07 AC 91 ms
7,316 KB
testcase_08 AC 89 ms
7,316 KB
testcase_09 AC 89 ms
7,316 KB
testcase_10 AC 90 ms
7,316 KB
testcase_11 AC 89 ms
7,316 KB
testcase_12 AC 90 ms
7,316 KB
testcase_13 AC 67 ms
6,548 KB
testcase_14 AC 38 ms
6,548 KB
testcase_15 AC 37 ms
6,548 KB
testcase_16 AC 55 ms
6,548 KB
testcase_17 AC 64 ms
6,548 KB
testcase_18 AC 72 ms
6,636 KB
testcase_19 AC 65 ms
6,548 KB
testcase_20 AC 66 ms
6,548 KB
testcase_21 AC 76 ms
6,884 KB
testcase_22 AC 64 ms
6,548 KB
testcase_23 AC 2 ms
6,548 KB
testcase_24 AC 2 ms
6,548 KB
testcase_25 AC 2 ms
6,548 KB
testcase_26 AC 2 ms
6,548 KB
testcase_27 AC 2 ms
6,548 KB
testcase_28 AC 58 ms
6,548 KB
testcase_29 AC 20 ms
6,548 KB
testcase_30 AC 20 ms
6,548 KB
testcase_31 AC 17 ms
6,548 KB
testcase_32 AC 54 ms
6,548 KB
testcase_33 AC 2 ms
6,548 KB
testcase_34 AC 2 ms
6,548 KB
testcase_35 AC 1 ms
6,548 KB
testcase_36 AC 2 ms
6,548 KB
testcase_37 AC 2 ms
6,548 KB
testcase_38 AC 2 ms
6,548 KB
testcase_39 AC 1 ms
6,548 KB
testcase_40 AC 2 ms
6,548 KB
testcase_41 AC 2 ms
6,548 KB
testcase_42 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <atcoder/modint>
using namespace std;
using i64 = long long;
using u64 = unsigned long long;
#define rep(i,n) for(i64 i=0; i<(i64)(n); i++)
#define repr(i,n) for(i64 i=(i64)(n)-1; i>=0; i--)
const i64 INF = 1001001001001001001;
using Modint = atcoder::static_modint<998244353>;

int main(){
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N, K; cin >> N >> K;
    vector<pair<int,int>> A(N);
    for(auto& [l,r] : A) cin >> l >> r;
    sort(A.begin(), A.end());
    vector<int> nx(N+1, N); {
        vector<int> fastend(N+1);
        rep(i,N+1) fastend[i] = i;
        for(int i=N-1; i>=1; i--){
            if(A[i-1].second > A[fastend[i]].second){
                fastend[i-1] = fastend[i];
            }
        }
        rep(i,N){
            int x = A[i].second;
            int p = lower_bound(A.begin(), A.end(), pair<int,int>(x,-1)) - A.begin();
            nx[i] = fastend[p];
        }
    }
    auto dbl = [&](const vector<int>& f) -> vector<int> {
        vector<int> res(N+1);
        rep(i,N+1) res[i] = f[f[i]];
        return res;
    };
    vector<int> tel(N+1);
    rep(i,N+1) tel[i] = i;
    rep(d,20){
        if((K-1)&(1<<d)) rep(i,N+1) tel[i] = nx[tel[i]];
        nx = dbl(nx);
    }
    int ans = 1001001001;
    rep(i,N+1) if(tel[i] < N) ans = min(ans, A[tel[i]].second - A[i].first);
    if(ans == 1001001001) ans = -1;
    cout << ans << endl;
    return 0;
}
0