結果

問題 No.2667 Constrained Permutation
ユーザー suisen
提出日時 2023-10-29 21:55:14
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 914 bytes
コンパイル時間 909 ms
コンパイル使用メモリ 99,096 KB
最終ジャッジ日時 2025-02-17 16:53:48
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 12 TLE * 1 -- * 33
権限があれば一括ダウンロードができます

ソースコード

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 ans = 0;
    for (int k = 0; k < lr.back().first; ++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;
        }
    }
    std::cout << ans << std::endl;
}
0