Submission #74572

#TimeUsernameProblemLanguageResultExecution timeMemory
74572wzyWatching (JOI13_watching)C++11
0 / 100
477 ms32172 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair<int,int> #define F first #define S second #define pb push_back #define int long long int n , p , q; vector<int> v; int dp[2002][2002]; deque<int> small, large; bool can(int mid){ for(int i = 0 ; i <= n ; i++){ for(int j = 0 ; j <= n; j ++) dp[i][j] = 2000000000; } for(int i = 0 ; i < n; i ++){ if(v[i] - v[0] + 1 <= mid) dp[i][1] = 0; if(v[i] - v[0] + 1 <= 2*mid) dp[i][0] = 1; } while(small.size()) small.pop_back(); while(large.size()) large.pop_back(); small.push_front(0) , large.push_front(0); for(int i = 1 ; i < n ; i++){ while(large.size() && v[i] - v[large.front()] + 1 > 2*mid){ large.pop_front(); } while(small.size() && v[i] - v[small.front()] + 1 > mid){ small.pop_front(); } for(int j = 0 ; j <= min(p , i+1) ; j++){ if(j) dp[i][j] = min(dp[i][j] , dp[i][j-1]); if(j && small.size() && small.front() > 0) dp[i][j] = min(dp[i][j] , dp[small.front() - 1][j-1]); if(large.size() && large.front() > 0) dp[i][j] = min(dp[i][j] , dp[large.front() - 1][j] + 1); dp[i][j] = min(dp[i][j] , 1 + dp[i-1][j]); } large.push_back(i); small.push_back(i); } for(int i = 0 ; i <= p ; i++){ if(dp[n-1][i] <= q) return true; } return false; } int32_t main(){ scanf("%lld%lld%lld" , &n , &p , &q); v.resize(n); for(int i = 0 ; i < n; i ++) scanf("%lld" , &v[i]); sort(v.begin() , v.end()); int l = 1 , r = 1000000000; int ansj = 1000000000; while(l<=r){ int mid = (l+r)/2; if(can(mid)){ ansj = mid; r = mid - 1; } else{ l = mid + 1; } } printf("%lld\n" , ansj); }

Compilation message (stderr)

watching.cpp: In function 'int32_t main()':
watching.cpp:49:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld%lld" , &n , &p , &q);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:51:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0 ; i < n; i ++) scanf("%lld" , &v[i]);
                               ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...