Submission #655152

# Submission time Handle Problem Language Result Execution time Memory
655152 2022-11-03T11:33:56 Z hail Watching (JOI13_watching) C++17
50 / 100
1000 ms 7764 KB
#include <bits/stdc++.h>
 
using namespace std;
 
#define vi vector<int>
#define vll vector<long long>
#define pb push_back
using ll= long long;
#define fast_io ios::sync_with_stdio(0); cin.tie(0)
#define inpint(x) int x; cin>>x
#define inpll(x) long long x; cin>>x
#define fl(i, n) for(int i=0; i<n; i++)
#define flo(i, n) for(int i=1; i<=n; i++)
#define int long long 
#define pi pair<int, int>
#define mp make_pair
#define ld long double

const int MOD = 7 + (int)1e9;
const int INF = (int)1e18;

//

int n, p, q;
int a[2005]{};

bool check(int w)
{
    int dp[p+1][q+1]{};
    //p small q large

    for(int i=0; i<=p; i++)
    {
        for(int j=0; j<=q; j++)
        {
            //check p, q-1 and p-1, q
            if(j-1>=0)
            {
                int x = dp[i][j-1];
                auto it = upper_bound(a+1, a+n+1, x);
                int y = *it;
                int z = y + (2*w) - 1;
                it = upper_bound(a+1, a+n+1, z);
                it--;
                int t = *it;
                dp[i][j] = max(dp[i][j], t);
            }
            if(i-1>=0)
            {
                int x = dp[i-1][j];
                auto it = upper_bound(a+1, a+n+1, x);
                int y = *it;
                int z = y + (w) - 1;
                it = upper_bound(a+1, a+n+1, z);
                it--;
                int t = *it;
                dp[i][j] = max(dp[i][j], t);   
            }

            if(dp[i][j]>=a[n]) return true;
        }
    }

    return false;
}

void solve()
{
    cin>>n>>p>>q;

    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
    }

    sort(a+1, a+n+1);

    int low = 1;
    int high = 10000000000LL;

    if(p+q>=n)
    {
        cout<<1;
        return;
    }

    //assert(p<=2000 && q<=2000);
    int cnt = 0;
    while(high>low)
    {
        int mid = (high+low)/2;
        if(check(mid)) high = mid;
        else low = mid+1;
        cnt++;
        assert(cnt<40);
    }

    assert(high==low);

    cout<<high;


}

signed main()
{
    fast_io;

    int t=1; 
    //cin>>t;
    while(t--)
    {
        solve();
    }
    cout<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 2 ms 212 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 3 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 213 ms 1044 KB Output is correct
9 Correct 197 ms 980 KB Output is correct
10 Correct 265 ms 1620 KB Output is correct
11 Correct 136 ms 1636 KB Output is correct
12 Execution timed out 1081 ms 7764 KB Time limit exceeded
13 Halted 0 ms 0 KB -