# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
21054 | 2017-04-04T05:52:35 Z | sbansalcs | Watching (JOI13_watching) | C++14 | 336 ms | 17724 KB |
#include <iostream> #include <algorithm> using namespace std; typedef long long ll; const int N = 2003; ll arr[N]; int A[N],B[N]; int dp[N][N]; int n,p,q; int bs(int f,ll a) { int lx=f+1,rx=n+1,mx; while (lx<rx) { mx=(lx+rx)/2; if(arr[mx]>=a) rx=mx; else lx=mx+1; } return lx; } bool check(ll w) { for (int i=1; i<=n; i++) { A[i]=bs(i,arr[i]+w); B[i]=bs(i,arr[i]+2*w); } for (int i=n+1; i>=1; i--) { for (int j=0; j<=q; j++) { if(i==n+1) dp[i][j]=0; else { dp[i][j]=1+dp[A[i]][j]; if(j!=0) { dp[i][j]=min(dp[i][j],dp[B[i]][j-1]); // dp[i][j]=min(dp[i][j],dp[i][j-1]); } } } } for (int i=0; i<=q; i++) { if(dp[1][i]<=p) return true; } // return dp[1][q]<=p; return false; } int main() { scanf("%d %d %d",&n,&p,&q); for (int i=1; i<=n; i++) { scanf("%lld",arr+i); } if(p+q>=n) { cout<<1<<endl;return 0; } sort(arr+1,arr+1+n); arr[n+1]=2e9; int lx=1,rx=1e9,mx; while (lx<rx) { mx=(lx+rx)/2; if(check(mx)) rx=mx; else lx=mx+1; } cout<<lx<<endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 17724 KB | Output is correct |
2 | Correct | 0 ms | 17724 KB | Output is correct |
3 | Correct | 0 ms | 17724 KB | Output is correct |
4 | Correct | 0 ms | 17724 KB | Output is correct |
5 | Correct | 0 ms | 17724 KB | Output is correct |
6 | Correct | 0 ms | 17724 KB | Output is correct |
7 | Correct | 0 ms | 17724 KB | Output is correct |
8 | Correct | 0 ms | 17724 KB | Output is correct |
9 | Correct | 0 ms | 17724 KB | Output is correct |
10 | Correct | 0 ms | 17724 KB | Output is correct |
11 | Correct | 0 ms | 17724 KB | Output is correct |
12 | Correct | 0 ms | 17724 KB | Output is correct |
13 | Correct | 0 ms | 17724 KB | Output is correct |
14 | Correct | 0 ms | 17724 KB | Output is correct |
15 | Correct | 0 ms | 17724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 17724 KB | Output is correct |
2 | Correct | 0 ms | 17724 KB | Output is correct |
3 | Correct | 0 ms | 17724 KB | Output is correct |
4 | Correct | 0 ms | 17724 KB | Output is correct |
5 | Correct | 0 ms | 17724 KB | Output is correct |
6 | Correct | 0 ms | 17724 KB | Output is correct |
7 | Correct | 9 ms | 17724 KB | Output is correct |
8 | Correct | 146 ms | 17724 KB | Output is correct |
9 | Correct | 26 ms | 17724 KB | Output is correct |
10 | Correct | 23 ms | 17724 KB | Output is correct |
11 | Correct | 336 ms | 17724 KB | Output is correct |
12 | Correct | 179 ms | 17724 KB | Output is correct |
13 | Correct | 13 ms | 17724 KB | Output is correct |
14 | Correct | 6 ms | 17724 KB | Output is correct |
15 | Correct | 9 ms | 17724 KB | Output is correct |