Submission #341440

#TimeUsernameProblemLanguageResultExecution timeMemory
341440bigDuckWatching (JOI13_watching)C++14
50 / 100
640 ms31980 KiB
#include<bits/stdc++.h> using namespace std; #define INIT ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define mp make_pair #define pb push_back #define ft first #define sc second #define ll long long #define pii pair<int, int> #define count_bits __builtin_popcount #define int ll int t, n, m, k, a[300010], q, p; int w; int dp[2010][2010]; void dinamica(){ for(int i=0; i<=min(n, p); i++){ dp[0][i]=0; } for(int i=1; i<=n; i++){ for(int j=0; j<=min(p, n); j++){ dp[i][j]=-1; } for(int j=i; j<=min(p, n); j++){ dp[i][j]=dp[i-1][j-1]; } int pt1=i, pt2=i; for(int j=i-1; j>=1; j--){ if( (a[i]-a[j]+1)<=(w) ){ pt1=j; } if( (a[i]-a[j]+1)<=(2*w) ){ pt2=j; } } for(int j=1; j<=min(p, n); j++){ if(dp[i][j]!=(-1)){ if( dp[pt1-1][j-1]!=(-1) ){ dp[i][j]=min(dp[i][j], dp[pt1-1][j-1]); } } else{ if( dp[pt1-1][j-1]!=(-1) ){ dp[i][j]=dp[pt1-1][j-1]; } } } for(int j=1; j<=min(p, n); j++){ if(dp[i][j]!=(-1)){ if( (dp[pt2-1][j]!=(-1)) ){ dp[i][j]=min(dp[i][j], dp[pt2-1][j]+1); } } else{ if( (dp[pt2-1][j]!=(-1)) ){ dp[i][j]=dp[pt2-1][j]+1; } } } } } bool verificare(){ for(int i=0; i<=min(p, n); i++){ if( (dp[n][i]<=q) && (dp[n][i]>(-1) ) ){ return true; } } return false; } void cautare(){ int l=1, r=1000000001, m=(l+r)>>1ll; while(l<r){ m=(l+r)>>1ll; w=m; dinamica(); if( verificare() ){ r=m; } else{ l=(m+1); } m=(l+r)>>1ll; } w=m; } int32_t main(){ INIT cin>>n>>p>>q; for(int i=1; i<=n; i++){ cin>>a[i]; } sort(a+1, a+n+1); cautare(); cout<<w; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...