Submission #777015

#TimeUsernameProblemLanguageResultExecution timeMemory
7770151binAliens (IOI16_aliens)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const ll NMAX = 5e5 + 5; ll n, x, y, bx = -1, dp[NMAX]; vector<pair<int, int>> tmp, v; ll m[NMAX], p[NMAX], sz, ii, cnt[NMAX]; int cross(int a, int b) { return 1.0 *(p[b] - p[a]) / (m[a] - m[b]); } int bad(int a, int b, int c){ return (p[b] - p[a]) * (m[b] - m[c]) >= (m[a] - m[b]) * (p[c] - p[b]);} ll get(int i, ll x){return m[i] * x + p[i];} void upd(ll mm, ll pp){ m[sz] = mm; p[sz] = pp; while(sz > 1 && bad(sz - 2, sz - 1, sz)){ m[sz - 1] = sz; p[sz - 1] = sz; if(--sz == ii) ii--; } sz++; return; } ll f(ll x){ while(ii + 1 < sz && get(ii, x) > get(ii + 1, x)) ii++; return get(ii, x); } int go(ll cost){ sz = ii = 0; auto&[x, y] = v[0]; upd(-2 * x, x * x); for(int i = 1; i <= n; i++){ auto&[x, y] = v[i - 1]; dp[i] = f(y + 1) + (y + 1) * (y + 1) + cost; cnt[i] = cnt[ii] + 1; if(i < n){ ll xx = v[i].first; ll dy = max(y + 1LL - xx, 0LL); upd(-2 * xx, xx * xx - dy * dy + dp[i]); } } return cnt[n]; } ll take_photos(int n_, int m, int k, vector<int> Y, vector<int> X) { n = n_; for(int i = 0; i < n; i++){ y = Y[i]; x = X[i]; if(x > y) swap(x, y); tmp.emplace_back(x, y); } sort(all(tmp)); for(auto& [x, y] : tmp){ if(x == bx) v.pop_back(); if(v.empty() || v.back().second < y) v.emplace_back(x, y); bx = x; } n = v.size(); ll l = 0, r = 1LL * m * m, mid; while(l < r){ mid = (l + r) / 2; if(go(mid) <= k) r = mid; else l = mid + 1; } go(l); return dp[n] - l * k; } /* int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> X(n), Y(n); for(int& x : X) cin >> x; for(int& y : Y) cin >> y; cout << take_photos(n, m, k, X, Y); return 0; } */
#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...