Submission #743407

# Submission time Handle Problem Language Result Execution time Memory
743407 2023-05-17T11:24:18 Z Valters07 Watching (JOI13_watching) C++14
50 / 100
1000 ms 16008 KB
#include <bits/stdc++.h>
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
#define en cin.close();return 0;
#define ll long long
#define pb push_back
#define fi first
#define se second
using namespace std;
const int N = 2e3+5;
int dp[N][N];// pos, c0 taken = min c1 taken
bool check(vector<int> &pos, int c0, int c1, int w)
{
    int n = pos.size()-1;
    for(int j = 0;j<=c0;j++)
    {
        int it0 = 1, it1 = 1;
        for(int i = 1;i<=n;i++)
        {
            while(pos[i]-pos[it0]+1>w)
                it0++;
            while(pos[i]-pos[it1]+1>2*w)
                it1++;
            dp[i][j]=dp[it1-1][j]+1;
            if(j>0)
                dp[i][j]=min(dp[i][j],dp[it0-1][j-1]);
        }
    }
    int minc1 = 1e9;
    for(int i = 0;i<=c0;i++)
        minc1=min(minc1,dp[n][i]);
    return (minc1<=c1);
}
int main()
{
//    ifstream cin("in.in");
    int n, c0, c1;
    cin >> n >> c0 >> c1;
    if(n<=c0+c1)
        return cout << 1, 0;
    vector<int> pos(n+1);
    for(int i = 1;i<=n;i++)
        cin >> pos[i];
    sort(pos.begin()+1,pos.end());
    for(int i = 1;i<=c0;i++)
        dp[0][i]=n;
    int l = 1, r = 1e9;
    while(l<r)
    {
        int mid = (l+r)/2;
        if(check(pos,c0,c1,mid))
            r=mid;
        else
            l=mid+1;
    }
    cout << l;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 0 ms 308 KB Output is correct
3 Correct 1 ms 304 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 596 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 692 KB Output is correct
11 Correct 2 ms 724 KB Output is correct
12 Correct 2 ms 724 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 1 ms 596 KB Output is correct
15 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 8300 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 320 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 16 ms 8464 KB Output is correct
8 Correct 82 ms 9196 KB Output is correct
9 Correct 587 ms 14256 KB Output is correct
10 Execution timed out 1016 ms 16008 KB Time limit exceeded
11 Halted 0 ms 0 KB -