Submission #197498

#TimeUsernameProblemLanguageResultExecution timeMemory
197498handlenameWatching (JOI13_watching)C++17
100 / 100
299 ms16376 KiB
#include <bits/stdc++.h> using namespace std; int arr[2001],w,n,memo[2005][2005]; int memo2[2005][2]; int dp(int index,int p){ if (index<p || index<0) return 0; if (index==0) return 1; if (memo[index][p]!=-1) return memo[index][p]; int x,y; if (memo2[index][0]!=-1){ x=memo2[index][0]; y=memo2[index][1]; } else { memo2[index][0]=x=upper_bound(arr,arr+n,arr[index]-2*w)-1-arr; memo2[index][1]=y=upper_bound(arr,arr+n,arr[index]-w)-1-arr; } if (p==0) return memo[index][p]=dp(x,p)+1; return memo[index][p]=min(dp(x,p)+1,dp(y,p-1)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int p,q; cin>>n>>p>>q; for (int i=0;i<n;i++) cin>>arr[i]; if (p+q>=n){ cout<<1; return 0; } memset(memo,-1,sizeof(memo)); sort(arr,arr+n); int mini=0,maxi=1000000000; while (mini+1<maxi){ w=(mini+maxi)/2; if (dp(n-1,p)>q) mini=w; else maxi=w; memset(memo,-1,sizeof(memo)); memset(memo2,-1,sizeof(memo2)); } cout<<maxi; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...