結果

問題 No.2543 Many Meetings
ユーザー 👑 tatyamtatyam
提出日時 2023-11-24 22:24:51
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 733 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 3,483 ms
コンパイル使用メモリ 263,696 KB
実行使用メモリ 202,752 KB
最終ジャッジ日時 2023-11-24 22:25:10
合計ジャッジ時間 16,301 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 581 ms
175,616 KB
testcase_04 AC 571 ms
175,744 KB
testcase_05 AC 575 ms
175,616 KB
testcase_06 AC 604 ms
175,488 KB
testcase_07 AC 572 ms
175,744 KB
testcase_08 AC 619 ms
154,368 KB
testcase_09 AC 640 ms
154,240 KB
testcase_10 AC 622 ms
154,880 KB
testcase_11 AC 606 ms
154,624 KB
testcase_12 AC 643 ms
154,368 KB
testcase_13 AC 589 ms
153,344 KB
testcase_14 AC 367 ms
86,400 KB
testcase_15 AC 261 ms
84,864 KB
testcase_16 AC 516 ms
126,848 KB
testcase_17 AC 609 ms
145,664 KB
testcase_18 AC 646 ms
188,672 KB
testcase_19 AC 606 ms
170,368 KB
testcase_20 AC 566 ms
172,160 KB
testcase_21 AC 733 ms
202,752 KB
testcase_22 AC 536 ms
166,656 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 37 ms
6,676 KB
testcase_29 AC 14 ms
6,676 KB
testcase_30 AC 14 ms
6,676 KB
testcase_31 AC 13 ms
6,676 KB
testcase_32 AC 33 ms
6,676 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 1 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 1 ms
6,676 KB
testcase_41 AC 2 ms
6,676 KB
testcase_42 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0