Submission #962580

#TimeUsernameProblemLanguageResultExecution timeMemory
962580MinaRagy06Aliens (IOI16_aliens)C++17
4 / 100
1 ms348 KiB
#include <bits/stdc++.h> #include "aliens.h" #ifdef MINA #include "grader.cpp" #endif using namespace std; #define ll long long #define lll __int128_t #define sz(x) (int) x.size() const int N = 100'005; const ll inf = 1e18; array<ll, 2> dp[N]; ll take_photos(int n, int crap, int m, vector<int> R, vector<int> C) { array<ll, 2> A[n + 1]; vector<ll> v; for (int i = 1; i <= n; i++) { A[i] = {R[i - 1], C[i - 1]}; if (A[i][0] > A[i][1]) swap(A[i][0], A[i][1]); } sort(A + 1, A + n + 1, [&] (array<ll, 2> x, array<ll, 2> y) {return make_pair(x[0], -x[1]) < make_pair(y[0], -y[1]);}); multiset<ll> s; vector<array<ll, 2>> a = {{0, 0}}; for (int i = 1; i <= n; i++) { while (s.size() && *s.begin() < A[i][0]) s.erase(s.begin()); if (s.size() && A[i][1] <= *s.rbegin()) continue; a.push_back({A[i][0], A[i][1]}); s.insert(A[i][1]); } n = a.size() - 1; ll prf[n + 2]{}; prf[1] = -1e18; for (int i = 1; i <= n; i++) { prf[i + 1] = max(prf[i], a[i][1]); a[i][0]--; prf[i] = max(prf[i], a[i][0]); a[i][0] *= -2; } auto check = [&] (ll c) { for (int i = 1; i <= n; i++) { dp[i] = {inf, inf}; } dp[0] = {0, 0}; auto cmp = [&] (int x, int y, int z) { return (lll) (prf[y] * (prf[y] + a[y][0]) - prf[x] * (prf[x] + a[x][0]) - dp[y - 1][0] + dp[x - 1][0]) * (a[z][0] - a[y][0]) >= (lll) (prf[z] * (prf[z] + a[z][0]) - prf[y] * (prf[y] + a[y][0]) - dp[z - 1][0] + dp[y - 1][0]) * (a[y][0] - a[x][0]); }; auto calc = [&] (int i, int k) { return a[i][1] * a[k][0] - prf[k] * prf[k] - prf[k] * a[k][0] + dp[k - 1][0]; }; deque<int> dq; int sz = 0; for (int i = 1; i <= n; i++) { while (sz - 2 >= 0 && cmp(dq[sz - 2], dq[sz - 1], i)) { dq.pop_back(); sz--; } dq.push_back(i); sz++; while (1 < sz && calc(i, dq[1]) <= calc(i, dq[0])) { dq.pop_front(); sz--; } dp[i][0] = calc(i, dq[0]) + a[i][1] * a[i][1] + c; dp[i][1] = dp[dq[0] - 1][1] + 1; } return dp[n][1] <= m; }; ll l = 0, r = inf; while (l <= r) { ll md = ((l + r) >> 1); if (check(md)) { r = md - 1; } else { l = md + 1; } } ll k = l; check(k); return dp[n][0] - k * m; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...