結果
問題 | No.2543 Many Meetings |
ユーザー |
![]() |
提出日時 | 2024-10-21 10:37:19 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 79 ms / 2,000 ms |
コード長 | 1,160 bytes |
コンパイル時間 | 2,505 ms |
コンパイル使用メモリ | 210,948 KB |
実行使用メモリ | 11,216 KB |
最終ジャッジ日時 | 2024-10-21 10:37:25 |
合計ジャッジ時間 | 5,818 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;int main(){cin.tie(nullptr);ios_base::sync_with_stdio(false);ll N, K, L, R, r=1, ans=1e18;cin >> N >> K;K--;vector<pair<ll, ll>> RL(N+1);for (int i=1; i<=N; i++){cin >> L >> R;RL[i] = {R, L};}sort(RL.begin(), RL.end());/*f(i) = iのミーティングに参加したとき、次に参加するミーティングR_i<=L_jかつR_jが最小のものを選ぶf^(K-1)(i)<=NならOK*/vector<ll> dp(N+2), v(N+2);for (int l=1; l<=N; l++){while(r <= N && RL[l].first > RL[r].second) r++;dp[l] = r;}dp[N+1] = N+1;iota(v.begin(), v.end(), 0);while(K){if (K&1){for (int i=1; i<=N; i++) v[i] = v[dp[i]];}vector<ll> pd(N+2);for (int i=1; i<=N+1; i++) pd[i] = dp[dp[i]];swap(dp, pd);K >>= 1;}for (int i=1; i<=N; i++){if (v[i] <= N){ans = min(ans, RL[v[i]].first-RL[i].second);}}cout << (ans != 1e18 ? ans : -1) << endl;return 0;}