Submission #51433

# Submission time Handle Problem Language Result Execution time Memory
51433 2018-06-18T02:18:09 Z combi2k2 Watching (JOI13_watching) C++14
50 / 100
1000 ms 16356 KB
#include<bits/stdc++.h>
using namespace std;
const int N = 2001;
int n, p, q;
int a[N];
int dp[N][N];
int BS(int l,int r,int val) {
    if(l == r)  return l;
    int m = (l + r) / 2;
    if(a[m] > val)  return BS(l,m,val);
    return BS(m + 1,r,val);
}
bool ch(int w)   {
    memset(dp,0,sizeof dp);
    for(int i = 0 ; i <= p ; ++i)
    for(int j = 0 ; j <= q ; ++j)    {
        if(i == 0 && j == 0)    continue;
        if(i > 0)   {
            int k = dp[i - 1][j] + 1;
            dp[i][j] = max(dp[i][j],BS(1,n + 1,a[k] + w - 1) - 1);
        }
        if(j > 0)   {
            int k = dp[i][j - 1] + 1;
            dp[i][j] = max(dp[i][j],BS(1,n + 1,a[k] + w * 2 - 1) - 1);
        }
        if(dp[i][j] == n)   return 1;
    }
    return 0;
}
int main()  {
    ios_base::sync_with_stdio(false);   cin.tie(0);
    cin >> n >> p >> q;
    if(p + q >= n)  {   cout << "1";    exit(0);    }
    for(int i = 1 ; i <= n ; ++i)
        cin >> a[i];
    sort(a + 1,a + 1 + n);
    int L = 1, R = 1e9;
    while(L != R)   {
        int M = (L + R) / 2;
        if(ch(M))   R = M;
        else        L = M + 1;
    }
    cout << L << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 40 ms 15992 KB Output is correct
2 Correct 2 ms 15992 KB Output is correct
3 Correct 54 ms 16140 KB Output is correct
4 Correct 2 ms 16140 KB Output is correct
5 Correct 2 ms 16140 KB Output is correct
6 Correct 2 ms 16140 KB Output is correct
7 Correct 45 ms 16272 KB Output is correct
8 Correct 46 ms 16272 KB Output is correct
9 Correct 42 ms 16272 KB Output is correct
10 Correct 42 ms 16272 KB Output is correct
11 Correct 46 ms 16272 KB Output is correct
12 Correct 43 ms 16356 KB Output is correct
13 Correct 44 ms 16356 KB Output is correct
14 Correct 53 ms 16356 KB Output is correct
15 Correct 45 ms 16356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 16356 KB Output is correct
2 Correct 2 ms 16356 KB Output is correct
3 Correct 2 ms 16356 KB Output is correct
4 Correct 2 ms 16356 KB Output is correct
5 Correct 2 ms 16356 KB Output is correct
6 Correct 2 ms 16356 KB Output is correct
7 Correct 52 ms 16356 KB Output is correct
8 Correct 300 ms 16356 KB Output is correct
9 Correct 259 ms 16356 KB Output is correct
10 Correct 258 ms 16356 KB Output is correct
11 Correct 196 ms 16356 KB Output is correct
12 Execution timed out 1083 ms 16356 KB Time limit exceeded
13 Halted 0 ms 0 KB -