結果

問題 No.2667 Constrained Permutation
ユーザー keisuke6keisuke6
提出日時 2024-03-09 00:11:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,190 bytes
コンパイル時間 2,338 ms
コンパイル使用メモリ 212,540 KB
実行使用メモリ 8,704 KB
最終ジャッジ日時 2024-03-09 00:12:06
合計ジャッジ時間 8,684 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
    int N;
    cin>>N;
    vector<pair<int,int>> S(N);
    for(int i=0;i<N;i++) cin>>S[i].first>>S[i].second;
    sort(S.begin(),S.end());
    int ind = 0;
    priority_queue<int,vector<int>,greater<int>> pq;
    int l = 1e18;
    for(int i=0;i<N;i++) l = min(l,S[i].first-(i+1));
    l = max(0ll,l);
    int ll = l;
    for(int i=S[0].first+l;i<S[0].first+N+l;i++){
        while(ind != N && S[ind].first <= i){
            pq.push(S[ind].second);
            ind++;
        }
        if(pq.empty() || pq.top() < i){
            cout<<0<<endl;
            return 0;
        }
        pq.pop();
    }
    for(int z=30;z>=0;z--){
        while(pq.size()) pq.pop();
        ind = 0;
        l += (1ll<<z);
        bool p = true;
        for(int i=S[0].first+l;i<S[0].first+N+l;i++){
            while(ind != N && S[ind].first <= i){
                pq.push(S[ind].second);
                ind++;
            }
            if(pq.empty() || pq.top() < i){
                p = false;
                break;
            }
            pq.pop();
        }
        if(!p) l -= (1<<z);
    }
    cout<<l-ll+1<<endl;
}
0