結果

問題 No.2543 Many Meetings
ユーザー maksimmaksim
提出日時 2023-11-24 22:15:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 1,719 ms
コンパイル使用メモリ 177,240 KB
実行使用メモリ 75,652 KB
最終ジャッジ日時 2023-11-24 22:16:04
合計ジャッジ時間 11,232 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 108 ms
69,172 KB
testcase_01 AC 101 ms
69,172 KB
testcase_02 AC 129 ms
69,172 KB
testcase_03 AC 253 ms
75,652 KB
testcase_04 AC 252 ms
75,652 KB
testcase_05 AC 254 ms
75,652 KB
testcase_06 AC 252 ms
75,652 KB
testcase_07 AC 256 ms
75,652 KB
testcase_08 AC 252 ms
75,652 KB
testcase_09 AC 254 ms
75,652 KB
testcase_10 AC 250 ms
75,652 KB
testcase_11 AC 258 ms
75,652 KB
testcase_12 AC 255 ms
75,652 KB
testcase_13 AC 250 ms
75,240 KB
testcase_14 AC 170 ms
71,936 KB
testcase_15 AC 169 ms
71,880 KB
testcase_16 AC 210 ms
73,232 KB
testcase_17 AC 218 ms
75,240 KB
testcase_18 AC 247 ms
75,240 KB
testcase_19 AC 263 ms
75,240 KB
testcase_20 AC 247 ms
75,240 KB
testcase_21 AC 255 ms
75,348 KB
testcase_22 AC 235 ms
75,240 KB
testcase_23 AC 106 ms
69,232 KB
testcase_24 AC 110 ms
69,192 KB
testcase_25 AC 106 ms
69,200 KB
testcase_26 AC 108 ms
69,200 KB
testcase_27 AC 109 ms
69,232 KB
testcase_28 AC 190 ms
75,240 KB
testcase_29 AC 126 ms
70,688 KB
testcase_30 AC 142 ms
70,712 KB
testcase_31 AC 123 ms
70,440 KB
testcase_32 AC 178 ms
75,240 KB
testcase_33 AC 107 ms
69,172 KB
testcase_34 AC 107 ms
69,172 KB
testcase_35 AC 107 ms
69,176 KB
testcase_36 AC 105 ms
69,172 KB
testcase_37 AC 102 ms
69,176 KB
testcase_38 AC 101 ms
69,172 KB
testcase_39 AC 116 ms
69,176 KB
testcase_40 AC 101 ms
69,172 KB
testcase_41 AC 102 ms
69,168 KB
testcase_42 AC 103 ms
69,172 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'int32_t main()':
main.cpp:18:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   18 |     for(auto [l,r]:v)
      |              ^

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define app push_back
const int maxn=4e5+5;
int arr[maxn];
int u[maxn][20];
const int inf=1e18;
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;cin>>n>>k;
    vector<pair<int,int> > v;vector<int> moms;
    for(int i=0;i<n;++i) {int l,r;cin>>l>>r;v.app({l,r});moms.app(l);moms.app(r);}
    sort(moms.begin(),moms.end());for(int i=0;i<v.size();++i) {v[i].first=lower_bound(moms.begin(),moms.end(),v[i].first)-moms.begin();v[i].second=lower_bound(moms.begin(),moms.end(),v[i].second)-moms.begin();}
    fill(arr,arr+maxn,inf);
    for(auto [l,r]:v)
    {
        arr[l]=min(arr[l],r);
    }
    for(int i=maxn-1;i>=1;--i) {arr[i-1]=min(arr[i-1],arr[i]);}
    for(int i=0;i<maxn;++i) u[i][0]=arr[i];
    for(int j=1;j<20;++j)
    {
        for(int i=0;i<maxn;++i)
        {
            if(u[i][j-1]==inf) u[i][j]=inf;
            else u[i][j]=u[u[i][j-1]][j-1];
        }
    }
    int res=inf;
    for(int i=0;i<maxn;++i)
    {
        int cur=i;
        for(int j=0;j<20;++j)
        {
            if(k & (1<<j))
            {
                if(cur!=inf)
                cur=u[cur][j];
            }
        }
        if(cur!=inf) res=min(res,moms[cur]-moms[i]);
    }
    cout<<(res==inf ? -1 : res);
    return 0;
}
0