結果

問題 No.2667 Constrained Permutation
ユーザー suisensuisen
提出日時 2023-10-29 22:52:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,240 bytes
コンパイル時間 1,005 ms
コンパイル使用メモリ 100,352 KB
実行使用メモリ 10,888 KB
最終ジャッジ日時 2024-01-15 12:25:42
合計ジャッジ時間 5,466 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,888 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 3 ms
6,676 KB
testcase_04 AC 4 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 3 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
testcase_43 -- -
testcase_44 -- -
testcase_45 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cassert>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);

    int n;
    std::cin >> n;

    std::vector<std::pair<int, int>> lr(n);
    for (auto& [l, r] : lr) std::cin >> l >> r;

    std::sort(lr.begin(), lr.end());

    int k = 0;
    for (int i = 1; i <= n; ++i) k = std::max(k, lr[i - 1].first - i);
    std::cerr << "min k = " << k << std::endl;

    int kr = 1000000000;
    for (int i = 0; i < n; ++i) kr = std::min(kr, lr[i].second - 1);

    int ans = 0;
    for (; k <= kr; ++k) {
        bool ok = true;

        std::priority_queue<int, std::vector<int>, std::greater<int>> pq;

        for (int i = 1, j = 0; i <= n; ++i) {
            while (j < n and lr[j].first <= k + i) {
                pq.push(lr[j++].second);
            }
            if (pq.empty() or pq.top() < k + i) {
                ok = false;
                break;
            }
            pq.pop();
        }
        if (ok) {
            ++ans;
        }
        if (ans and not ok) {
            std::cerr << "max k = " << k - 1 << std::endl;
            break;
        }
    }
    std::cout << ans << std::endl;
}
0