# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1059193 | 2024-08-14T18:27:50 Z | vjudge1 | Watching (JOI13_watching) | C++17 | 4 ms | 604 KB |
#include <bits/stdc++.h> using namespace std; bool check(long long w,vector<long long> dp1[],vector<long long> dp2[],long long n,long long p,long long q,vector<long long> vec) { dp1[0][p]=q; dp2[0][q]=p; vec.push_back(2000000000); for(long long i=0;i<n;i++) { for(long long j=p;j>0;j--) { long long br=vec[i]+w-1; for(long long k=i+1;k<=n;k++) { if(vec[k]>br) { dp1[k][j-1]=max(dp1[k][j-1],dp1[i][j]); dp2[k][dp1[i][j]]=max(dp2[k][dp1[i][j]],j-1); break; } } } for(long long j=q;j>0;j--) { long long br=vec[i]+2*w-1; for(long long k=i+1;k<=n;k++) { if(vec[k]>br) { dp2[k][j-1]=max(dp2[k][j-1],dp2[i][j]); dp1[k][dp2[i][j]]=max(dp1[k][dp2[i][j]],j-1); break; } } } } for(long long i=p;i>=0;i--) { if(dp1[n][i]!=-1) return true; } for(long long i=q;i>=0;i--) { if(dp2[n][i]!=-1) return true; } } int main() { long long n,p,q; cin>>n>>p>>q; vector<long long> vec; for(long long n1=n;n1>0;n1--) { long long x; cin>>x; vec.push_back(x); } sort(vec.begin(),vec.end()); vector<long long> dp1[n+1]; vector<long long> temp; for(long long i=p;i>=0;i--) { temp.push_back(-1); } for(long long i=0;i<=n;i++) dp1[i]=(temp); vector<long long> dp2[n+1]; temp.clear(); for(long long i=q;i>=0;i--) { temp.push_back(-1); } for(long long i=0;i<=n;i++) dp2[i]=(temp); if(p+q>=n) { cout<<1; return 0; } long long l=1,r=1000000000; long long m=(l+r)/2; for(;l<=r;m=(l+r)/2) { temp.clear(); for(long long i=p;i>=0;i--) { temp.push_back(-1); } for(long long i=0;i<=n;i++) dp1[i]=(temp); temp.clear(); for(long long i=q;i>=0;i--) { temp.push_back(-1); } for(long long i=0;i<=n;i++) dp2[i]=(temp); bool pos=check(m,dp1,dp2,n,p,q,vec); if(pos==false) { l=m+1; } else r=m-1; } cout<<l; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 604 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |