Submission #1196861

#TimeUsernameProblemLanguageResultExecution timeMemory
1196861InvMODWatching (JOI13_watching)C++17
100 / 100
832 ms16192 KiB
#include<bits/stdc++.h>

using namespace std;

#define fi first
#define se second
#define pb push_back
#define eb emplace_back

#define vi vector<int>
#define pi pair<int,int>
#define sz(v) (int)(v).size()
#define all(v) (v).begin(), (v).end()
#define compact(v) (v).erase(unique(all(v)), (v).end())

template<class T> using upq = priority_queue<T, vector<T>, greater<T>>;
template<class T> int lwrbound(const vector<T>& a, const T& b, const int s = 0){return int(lower_bound(s + all(a), b) - a.begin());}
template<class T> int uprbound(const vector<T>& a, const T& b, const int s = 0){return int(upper_bound(s + all(a), b) - a.begin());}

#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define sumof(x) accumulate(all(x), 0ll)
#define dbg(x) "[" << #x " = " << (x) << "]"
#define el "\n"

using ll = long long;
using ld = long double;

template<class T> bool ckmx(T& a, const T b){return (a < b ? a = b, true : false);}
template<class T> bool ckmn(T& a, const T b){return (a > b ? a = b, true : false);}

const int N = 2e5 + 5;
const int MOD = 1e9 + 7;
const ll INF = 2e9;


void Main()
{
    int n,p,q; cin >> n >> p >> q;

    vi a(n + 1); FOR(i, 1, n) cin >> a[i];

    ckmn(p, n), ckmn(q, n); sort(1 + all(a));

    auto ok = [&](int w) -> bool{
        vector<vi> dp(p + 1, vi(q + 1, 1));

        FOR(i, 0, p){
            FOR(j, 0, q){
                int x = dp[i][j];
                if(x > n) return true;

                int p1 = uprbound(a, (int) min(INF, a[x] + 1ll * w - 1));
                int p2 = uprbound(a, (int) min(INF, a[x] + 2ll * w - 1));

                if(i < p) ckmx(dp[i + 1][j], p1);
                if(j < q) ckmx(dp[i][j + 1], p2);
            }
        }
        return false;
    };

    int l = 0, r = 1e9 + 1;
    while(l + 1 < r){
        int m = l+r>>1;
        if(ok(m)){
            r = m;
        }
        else l = m;
    }
    cout << r << el;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    #define name "InvMOD"
    if(fopen(name".INP", "r")){
        freopen(name".INP", "r", stdin);
        freopen(name".OUT", "w", stdout);
    }

    int t = 1; while(t--) Main();
    return 0;
}

Compilation message (stderr)

watching.cpp: In function 'int32_t main()':
watching.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(name".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(name".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...