Submission #66660

#TimeUsernameProblemLanguageResultExecution timeMemory
66660HellAngelWatching (JOI13_watching)C++14
100 / 100
70 ms9268 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 2001; int n, a[maxn], f[maxn][maxn], p, q, Next[maxn][2]; int bs(int x) { int l = 1; int h = n; while(l <= h) { int mid = l + h >> 1; if(a[mid] < x) l = mid + 1; else h = mid - 1; } return l; } bool Check(int gau) { for(int i = 1; i <= n; i++) { Next[i][0] = bs(a[i] + gau); Next[i][1] = bs(a[i] + 2 * gau); } f[0][0] = 1; for(int i = 0; i <= p; i++) { for(int j = 0; j <= q; j++) { if(i == 0 && j == 0) continue; int x = 0; if(i > 0) { x = max(x, Next[f[i - 1][j]][0]); } if(j > 0) { x = max(x, Next[f[i][j - 1]][1]); } if(x == n + 1) return true; f[i][j] = x; } } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("test.inp", "r", stdin); //freopen("test.out", "w", stdout); cin >> n >> p >> q; for(int i = 1; i <= n; i++) { cin >> a[i]; } sort(a + 1, a + n + 1); if(p + q >= n) return cout << 1, 0; int l = 1; int h = 1e9; while(l <= h) { int mid = (l + h) / 2; if(Check(mid)) h = mid - 1; else l = mid + 1; } cout << l; }

Compilation message (stderr)

watching.cpp: In function 'int bs(int)':
watching.cpp:15:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
         int mid = l + h >> 1;
                   ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...