Submission #638577

#TimeUsernameProblemLanguageResultExecution timeMemory
638577ghostwriterWatching (JOI13_watching)C++14
100 / 100
405 ms16032 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include <debug.h> #endif #define st first #define nd second #define pb push_back #define pf push_front #define _pb pop_back #define _pf pop_front #define lb lower_bound #define ub upper_bound #define mtp make_tuple #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ldb; typedef pair<int, int> pi; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pi> vpi; typedef vector<pll> vpll; typedef string str; template<typename T> T gcd(T a, T b) { return (b == 0? a : gcd(b, a % b)); } template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i)) #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i)) #define EACH(i, x) for (auto &(i) : (x)) #define WHILE while #define file "TEST" mt19937 rd(chrono::steady_clock::now().time_since_epoch().count()); ll rand(ll l, ll r) { return uniform_int_distribution<ll>(l, r)(rd); } /* Tran The Bao CTL - Da Lat Cay ngay cay dem nhung deo duoc cong nhan */ const int oo = 1e9; const int N = 2e3 + 2; int n, p, q, a[N], d[N][N], f[N], f1[N]; bool check(int w) { FOR(i, 1, n) { FOS(j, i, 1) { if (a[j] >= a[i] - w + 1) f[i] = j; if (a[j] >= a[i] - 2 * w + 1) f1[i] = j; } } FOR(i, 1, n) FOR(j, 0, p) { d[i][j] = oo; if (j) { int pos = f[i]; d[i][j] = min(d[i][j], d[pos - 1][j - 1]); } int pos = f1[i]; d[i][j] = min(d[i][j], d[pos - 1][j] + 1); } return d[n][p] <= q; } signed main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); // freopen(file".inp", "r", stdin); // freopen(file".out", "w", stdout); cin >> n >> p >> q; FOR(i, 1, n) cin >> a[i]; sort(a + 1, a + 1 + n); p = min(p, n); q = min(q, n); int l = 1, r = 1e9, ans = -1; WHILE(l <= r) { int mid = l + (r - l) / 2; if (check(mid)) { ans = mid; r = mid - 1; } else l = mid + 1; } cout << ans; return 0; }

Compilation message (stderr)

watching.cpp: In function 'bool check(int)':
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:40:2: note: in expansion of macro 'FOR'
   40 |  FOR(i, 1, n) {
      |  ^~~
watching.cpp:25:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   25 | #define FOS(i, r, l) for (int (i) = (r); (i) >= (l); --(i))
      |                               ^
watching.cpp:41:3: note: in expansion of macro 'FOS'
   41 |   FOS(j, i, 1) {
      |   ^~~
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:46:2: note: in expansion of macro 'FOR'
   46 |  FOR(i, 1, n)
      |  ^~~
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'j' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:47:2: note: in expansion of macro 'FOR'
   47 |  FOR(j, 0, p) {
      |  ^~~
watching.cpp: In function 'int main()':
watching.cpp:24:31: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
   24 | #define FOR(i, l, r) for (int (i) = (l); (i) <= (r); ++(i))
      |                               ^
watching.cpp:63:5: note: in expansion of macro 'FOR'
   63 |     FOR(i, 1, n) cin >> a[i];
      |     ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...