結果

問題 No.2667 Constrained Permutation
ユーザー k1suxuk1suxu
提出日時 2024-03-08 23:46:17
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,095 bytes
コンパイル時間 3,265 ms
コンパイル使用メモリ 258,492 KB
実行使用メモリ 26,004 KB
最終ジャッジ日時 2024-03-08 23:46:27
合計ジャッジ時間 8,540 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,352 KB
testcase_01 AC 2 ms
6,548 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 TLE -
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 #

// #pragma GCC target("avx")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i = 0; i < (int)n; i++)
#define FOR(n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define all(x) x.begin(),x.end()
//#define mp make_pair
#define vi vector<int>
#define vvi vector<vi>
#define vvvi vector<vvi>
#define vvvvi vector<vvvi>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>

template<typename T>
bool chmax(T &a, const T b) {if(a<b) {a=b; return true;} else {return false;}}
template<typename T>
bool chmin(T &a, const T b) {if(a>b) {a=b; return true;} else {return false;}}

using ll = long long;
using ld = long double;
using ull = unsigned long long;

const ll INF = numeric_limits<long long>::max() / 2;
const ld pi = 3.1415926535897932384626433832795028;
const ll mod = 998244353;
int dx[] = {1, 0, -1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};

#define int long long

void solve() {
    int n;
    cin >> n;
    vi l(n), r(n);
    FOR(n) cin >> l[i] >> r[i];
    vector<int> order(n);
    iota(all(order), 0);
    sort(all(order), [&](int i, int j) -> bool {
        return l[i] < l[j];
    });
    int left = -1, right = INF;
    while(right-left > 1) {
        int mid = (left+right)/2;

        vi old_l = l, old_r = r;
        FOR(n) {
            l[i] -= mid;
            r[i] -= mid;
            chmax(l[i], 1LL);
        }

        multiset<int> mt;
        int id = 0;
        bool flag = true;
        repi(i, 1, n+1) {
            while(id < n && l[order[id]] == i) {
                mt.insert(r[order[id]]);
                ++id;
            }
            if(*mt.begin() < i) {
                flag = false;
                break;
            }
            mt.erase(mt.begin());
        }

        l = old_l;
        r = old_r;

        if(flag) left = mid;
        else right = mid;
    }
    cout << left+1 << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}
0