結果
| 問題 | No.2543 Many Meetings | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2023-11-24 22:15:52 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 403 ms / 2,000 ms | 
| コード長 | 1,328 bytes | 
| コンパイル時間 | 2,171 ms | 
| コンパイル使用メモリ | 176,076 KB | 
| 実行使用メモリ | 75,336 KB | 
| 最終ジャッジ日時 | 2024-09-26 09:27:54 | 
| 合計ジャッジ時間 | 13,249 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 40 | 
コンパイルメッセージ
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)
      |              ^
            
            ソースコード
#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;
}
            
            
            
        