結果

問題 No.2667 Constrained Permutation
ユーザー みここみここ
提出日時 2024-03-08 22:03:43
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 554 ms / 2,000 ms
コード長 1,064 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 85,384 KB
実行使用メモリ 8,544 KB
最終ジャッジ日時 2024-03-08 22:03:56
合計ジャッジ時間 10,701 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
6,548 KB
testcase_01 AC 3 ms
6,548 KB
testcase_02 AC 4 ms
6,548 KB
testcase_03 AC 4 ms
6,548 KB
testcase_04 AC 4 ms
6,548 KB
testcase_05 AC 4 ms
6,548 KB
testcase_06 AC 4 ms
6,548 KB
testcase_07 AC 3 ms
6,548 KB
testcase_08 AC 4 ms
6,548 KB
testcase_09 AC 4 ms
6,548 KB
testcase_10 AC 3 ms
6,548 KB
testcase_11 AC 4 ms
6,548 KB
testcase_12 AC 151 ms
6,548 KB
testcase_13 AC 7 ms
6,548 KB
testcase_14 AC 443 ms
8,416 KB
testcase_15 AC 178 ms
8,160 KB
testcase_16 AC 122 ms
6,752 KB
testcase_17 AC 42 ms
6,548 KB
testcase_18 AC 528 ms
8,544 KB
testcase_19 AC 386 ms
8,544 KB
testcase_20 AC 422 ms
8,544 KB
testcase_21 AC 222 ms
8,544 KB
testcase_22 AC 228 ms
8,544 KB
testcase_23 AC 228 ms
8,544 KB
testcase_24 AC 259 ms
6,624 KB
testcase_25 AC 497 ms
8,288 KB
testcase_26 AC 552 ms
8,544 KB
testcase_27 AC 554 ms
8,544 KB
testcase_28 AC 199 ms
8,160 KB
testcase_29 AC 201 ms
8,032 KB
testcase_30 AC 210 ms
8,160 KB
testcase_31 AC 124 ms
6,748 KB
testcase_32 AC 28 ms
6,548 KB
testcase_33 AC 212 ms
8,416 KB
testcase_34 AC 117 ms
6,752 KB
testcase_35 AC 134 ms
6,880 KB
testcase_36 AC 128 ms
6,880 KB
testcase_37 AC 150 ms
7,004 KB
testcase_38 AC 176 ms
8,160 KB
testcase_39 AC 5 ms
6,548 KB
testcase_40 AC 114 ms
6,752 KB
testcase_41 AC 184 ms
8,288 KB
testcase_42 AC 267 ms
6,752 KB
testcase_43 AC 282 ms
8,160 KB
testcase_44 AC 205 ms
6,548 KB
testcase_45 AC 9 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int n;
    cin >> n;
    P p[200005];
    for (int i = 0; i < n; i++)
    {
        cin >> p[i].first >> p[i].second;
    }
    int l = 0;
    sort(p, p + n);
    for (int i = 0; i < n; i++)
    {
        l = max(l, p[i].first - (i + 1));
    }
    ll ok = l - 1, ng = 2000000000;
    while (abs(ok - ng) > 1)
    {
        ll k = (ok + ng) / 2;
        int j = 0;
        priority_queue<ll, vector<ll>, greater<ll>> que;
        bool f = true;
        for (int i = 1; i <= n; i++)
        {
            while (j < n && p[j].first <= i + k)
            {
                que.push(p[j++].second);
            }
            if (!que.size() || que.top() < i + k)
            {
                f = false;
                break;
            }
            que.pop();
        }
        if (f)
        {
            ok = k;
        }
        else
        {
            ng = k;
        }
    }
    cout << ok - l + 1 << endl;
}
0