結果

問題 No.2543 Many Meetings
ユーザー fumofumofunifumofumofuni
提出日時 2023-11-25 18:35:51
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,426 bytes
コンパイル時間 2,778 ms
コンパイル使用メモリ 217,256 KB
実行使用メモリ 65,900 KB
最終ジャッジ日時 2023-11-25 18:36:02
合計ジャッジ時間 10,179 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 WA -
testcase_02 AC 2 ms
6,676 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 AC 258 ms
65,900 KB
testcase_09 AC 261 ms
65,900 KB
testcase_10 AC 270 ms
65,900 KB
testcase_11 AC 259 ms
65,900 KB
testcase_12 AC 260 ms
65,900 KB
testcase_13 AC 238 ms
52,788 KB
testcase_14 AC 135 ms
31,360 KB
testcase_15 AC 133 ms
30,848 KB
testcase_16 AC 200 ms
44,252 KB
testcase_17 AC 260 ms
50,332 KB
testcase_18 AC 274 ms
56,116 KB
testcase_19 AC 262 ms
51,520 KB
testcase_20 AC 262 ms
51,808 KB
testcase_21 AC 306 ms
59,800 KB
testcase_22 AC 243 ms
50,372 KB
testcase_23 AC 3 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 3 ms
6,676 KB
testcase_28 AC 134 ms
49,332 KB
testcase_29 AC 46 ms
18,816 KB
testcase_30 AC 47 ms
19,200 KB
testcase_31 AC 40 ms
16,384 KB
testcase_32 AC 125 ms
46,232 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;
//#pragma GCC optimize("Ofast")

#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,1,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a >= b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(){
    ll n,k;cin >> n >> k;
    vector<pair<pl,ll>> v(n);
    rep(i,n)cin >> v[i].first.first >> v[i].first.second;
    rep(i,n)v[i].second=i;
    auto nl=v;sort(all(nl));
    auto nr=v;sort(all(nr),[](pair<pl,ll> a,pair<pl,ll> b){return a.first.second<b.first.second;});
    ll rx=INF,idx=-1,now=n-1;
    vvl dp(30,vl(n));
    per(i,n){
        while(now>=0&&nl[now].first.first>=nr[i].first.second){
            if(chmin(rx,nl[now].first.second))idx=nl[now].second;
            now--;
        }
        dp[0][nr[i].second]=idx;
    }
    //rep(i,n)cout << dp[0][i] <<" ";cout << endl;
    rep(j,29){
        rep(i,n){
            if(dp[j][i]==-1){
                dp[j+1][i]=-1;
            }
            else {
                dp[j+1][i]=dp[j][dp[j][i]];
            }
        }
    }
    //rep(i,n)cout << dp[0][i] <<" ";cout << endl;
    //rep(i,n)cout << dp[1][i] <<" ";cout << endl;
    k--;
    ll ans=INF;
    rep(i,n){
        ll now=i;
        rep(j,30){
            if(now==-1)break;
            if(k>>j&1)now=dp[j][now];
        }
        //cout << now << endl;
        if(now!=-1){
            //cout << v[now].first.second <<" " << v[i].first.first << endl;
            chmin(ans,v[now].first.second-v[i].first.first);
            //cout << now <<" " << i << endl;
        }
    }
    cout << ans << endl;

}

0