Submission #474507

#TimeUsernameProblemLanguageResultExecution timeMemory
474507Urvuk3Watching (JOI13_watching)C++17
100 / 100
401 ms16524 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const ll MAXN=2e3+1,MAXA=5e6+5,INF=1e9,LINF=1e18; #define fi first #define se second #define pll pair<ll,ll> #define pii pair<int,int> #define mid (l+r)/2 #define sz(a) int((a).size()) #define all(a) a.begin(),a.end() #define mod 1000000007LL #define pb push_back #define endl "\n" #define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush; #define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());} #define pb push_back #define pf push_front #define ppf pop_front #define ppb pop_back #define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; } #pragma GCC optimize("Ofast") #pragma GCC target("fma,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("unroll-loops") ll n,m,k,p,q,x,y,z,res=INF,l,r; string s,t; vector<int> a; ifstream input; ofstream output; #ifdef ONLINE_JUDGE #define input cin #define output cout #endif bool check(int w){ int idxp=1,idxq=1; vector<vector<int>> dp(MAXN,vector<int>(MAXN,0)); ///dp[i][j] najmanji broj velikih kamera da bi uz pomoc njih i j kamera prekrili prvih i eventova for(int i=1;i<=n;i++){ while(a[i]-a[idxp]+1>w) idxp++; while(a[i]-a[idxq]+1>2*w) idxq++; ///PRINT(idxp); PRINT(idxq); for(int j=0;j<=p;j++){ ///broj manjih kamera dp[i][j]=INF; if(j) dp[i][j]=dp[idxp-1][j-1]; dp[i][j]=min(dp[i][j],dp[idxq-1][j]+1); } } /* cerr<<"dp:"<<endl; for(int i=1;i<=n;i++){ for(int j=0;j<=p;j++){ cerr<<dp[i][j]<<" "; } cerr<<endl; } */ ///PRINT(p); return dp[n][p]<=q; } void solve(){ cin>>n>>p>>q; p=min(n,p); q=min(n,q); a.resize(n+1); for(int i=1;i<=n;i++) cin>>a[i]; sort(a.begin()+1,a.end()); l=1,r=INF; while(l<=r){ if(check(mid)){ res=mid; r=mid-1; } else{ l=mid+1; } } cout<<res<<endl; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); #ifndef ONLINE_JUDGE input.open("D:\\UROS\\Programiranje\\input.in",ios::in); output.open("D:\\UROS\\Programiranje\\output.out",ios::out|ios::trunc); #endif //freopen(".in","r",stdin); //freopen(".out","w",stdout); int t; //cin>>t; t=1; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...