Submission #863942

#TimeUsernameProblemLanguageResultExecution timeMemory
863942prohackerWatching (JOI13_watching)C++14
100 / 100
204 ms16216 KiB
#include <bits/stdc++.h> #define ll long long #define ld long double using namespace std; const int N = 2010; const int INF = INT_MAX; const int mod = 1e9+7; int n,p,q,a[N]; int dp[N][N]; bool check(int mid) { for(int i = 1 ; i <= n ; i++) { for(int j = 0 ; j <= q ; j++) { dp[i][j] = mod; } } for(int i = 1, j = 1, k = 1 ; i <= n ; i++) { while(j < i && a[i]-a[j] >= mid) { j++; } while(k < i && a[i]-a[k] >= mid*2) { k++; } for(int l = 0 ; l <= q ; l++) { dp[i][l] = dp[j-1][l]+1; } for(int l = 0 ; l <= q ; l++) { dp[i][l+1] = min(dp[i][l+1],dp[k-1][l]); } } for(int i = 0 ; i <= q ; i++) { if(dp[n][i] <= p) { return true; } } return false; } signed main() { if (fopen("WATCHING.inp", "r")) { freopen("WATCHING.inp", "r", stdin); freopen("WATCHING.out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> p >> q; if(n <= p+q) { cout << 1; return 0; } for(int i = 1 ; i <= n ; i++) { cin >> a[i]; } sort(a+1,a+n+1); int l = 1; int r = 1e9; int ans; while(l <= r) { int mid = l + r >> 1; if(check(mid)) { ans = mid; r = mid-1; } else { l = mid+1; } } cout << ans; return 0; }

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:64:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   64 |         int mid = l + r >> 1;
      |                   ~~^~~
watching.cpp:45:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         freopen("WATCHING.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:46:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |         freopen("WATCHING.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
watching.cpp:73:13: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
   73 |     cout << ans;
      |             ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...