結果
問題 | No.2543 Many Meetings |
ユーザー |
👑 ![]() |
提出日時 | 2023-11-24 22:24:51 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 726 ms / 2,000 ms |
コード長 | 1,328 bytes |
コンパイル時間 | 3,447 ms |
コンパイル使用メモリ | 262,344 KB |
実行使用メモリ | 202,624 KB |
最終ジャッジ日時 | 2024-09-26 09:32:05 |
合計ジャッジ時間 | 15,954 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 40 |
ソースコード
#include <bits/stdc++.h> using namespace std; using i64 = int64_t; const i64 INF = LLONG_MAX / 4; void chmin(i64& a, i64 b) { if(a > b) a = b; } int main() { cin.tie(0)->sync_with_stdio(0); i64 N, K; cin >> N >> K; vector<pair<i64, i64>> A(N); map<i64, i64> nx_end; for(auto& [L, R] : A) { cin >> L >> R; chmin(nx_end.try_emplace(L, R).first->second, R); } { i64 mn = INF; for(auto& [key, val] : nx_end | views::reverse) { chmin(mn, val); val = mn; } } map<i64, i64> nx[18]; nx[0] = nx_end; for(i64 l = 0; l + 1 < 18; l++) { auto p = nx[l].begin(); for(auto [key, val] : nx[l]) { while(p != nx[l].end() && p->first < val) p++; if(p == nx[l].end()) break; nx[l + 1].emplace_hint(nx[l + 1].end(), key, p->second); } } i64 ans = INF; for(const i64 L : nx[0] | views::keys) { i64 R = L; for(i64 l = 18; l--; ) if(K & 1 << l) { auto p = nx[l].lower_bound(R); if(p == nx[l].end()) { if(ans == INF) ans = -1; cout << ans << endl; return 0; } R = p->second; } chmin(ans, R - L); } cout << ans << endl; }