Submission #22976

#TimeUsernameProblemLanguageResultExecution timeMemory
22976BruteforcemanWatching (JOI13_watching)C++11
100 / 100
296 ms21332 KiB
#include <bits/stdc++.h> using namespace std; int N, P, Q; int a[2222]; int big[2222]; int tiny[2222]; int search(int b, int e, int val) { if(b == e) { return b; } int m = (b + e) >> 1; if(val < a[m]) return search(b, m, val); else return search(m + 1, e, val); } const int inf = 1e8; int dp[2222][2222]; bool good(int w) { for(int i = 1; i <= N; i++) { tiny[i] = search(1, N, a[i] - w) - 1; big[i] = search(1, N, a[i] - w - w) - 1; } for(int i = 1; i <= N; i++) { for(int j = 0; j <= P; j++) { dp[i][j] = inf; if(j) dp[i][j] = min(dp[i][j], dp[tiny[i]][j - 1]); dp[i][j] = min(dp[i][j], dp[big[i]][j] + 1); } } return (dp[N][P] <= Q); } int find(int b, int e) { if(b == e) { return b; } int m = (b + e) >> 1; if(good(m)) return find(b, m); else return find(m + 1, e); } int main() { scanf("%d %d %d", &N, &P, &Q); for(int i = 1; i <= N; i++) { scanf("%d", &a[i]); } sort(a + 1, a + N + 1); if(N <= P || N <= Q) { printf("%d\n", 1); exit(0); } printf("%d\n", find(1, 1000000000)); return 0; }

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:46:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &N, &P, &Q);
                                  ^
watching.cpp:48:27: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
                           ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...