Submission #44563

#TimeUsernameProblemLanguageResultExecution timeMemory
44563chpipisWatching (JOI13_watching)C++11
100 / 100
323 ms16920 KiB
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define pf push_front #define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++) #define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL) #define all(v) (v).begin(), (v).end() #define rep(i, s, e) for (int i = s; i < e; i++) // START for segment tree #define params int p, int L, int R #define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1 // END #ifdef __linux__ #define gc getchar_unlocked #define pc putchar_unlocked #else #define gc getchar #define pc putchar #endif #if __cplusplus <= 199711L template<class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template<class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) { advance(it, n); return it; } #endif typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef long double ldouble; const double EPS = 1e-9; const double PI = 3.141592653589793238462; template<typename T> inline T sq(T a) { return a * a; } //#ifdef LOCAL_MACHINE //#endif const int MAXN = 2005; int n, p, q; int ev[MAXN], dp[MAXN][MAXN]; int prep[MAXN], preq[MAXN]; bool can(int w) { int ptr = 0; for (int i = 1; i <= n; i++) { while (ptr < i && ev[i] - w + 1 > ev[ptr]) ptr++; prep[i] = ptr - 1; } ptr = 0; for (int i = 1; i <= n; i++) { while (ptr < i && ev[i] - 2 * w + 1 > ev[ptr]) ptr++; preq[i] = ptr - 1; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= q; j++) { dp[i][j] = dp[prep[i]][j] + 1; if (j > 0) dp[i][j] = min(dp[i][j], dp[preq[i]][j - 1]); } } //printf("can(%d) ? %d\n", w, (int)(dp[n][q] <= p)); return dp[n][q] <= p; } int main() { //freopen("", "r", stdin); //freopen("", "w", stdout); scanf("%d %d %d", &n, &p, &q); ev[0] = -2e9; for (int i = 1; i <= n; i++) scanf("%d", &ev[i]); sort(ev + 1, ev + n + 1); if (p + q >= n) { puts("1"); } else { int lo = 1, hi = 1e9; while (lo < hi) { int mid = (lo + hi) >> 1; if (can(mid)) { hi = mid; } else { lo = mid + 1; } } printf("%d\n", hi); } return 0; }

Compilation message (stderr)

watching.cpp: In function 'int main()':
watching.cpp:90:10: 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:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &ev[i]);
         ~~~~~^~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...