Submission #777733

#TimeUsernameProblemLanguageResultExecution timeMemory
7777331binAliens (IOI16_aliens)C++14
100 / 100
93 ms9524 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<ll, ll>> tmp, v; ll m[NMAX], p[NMAX], sz, ii, cnt[NMAX]; 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, int c){ m[sz] = mm; p[sz] = pp; cnt[sz] = c; while(sz > 1 && bad(sz - 2, sz - 1, sz)){ m[sz - 1] = m[sz]; p[sz - 1] = p[sz]; cnt[sz - 1] = cnt[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); } pair<ll, ll> go(ll cost){ sz = ii = 0; auto&[x, y] = v[0]; upd(-2 * x, x * x, 0); for(int i = 1; i <= n; i++){ auto&[x, y] = v[i - 1]; dp[i] = f(y + 1) + (y + 1) * (y + 1) + cost; if(i < n){ ll xx = v[i].first; ll dy = max(y + 1LL - xx, 0LL); upd(-2 * xx, xx * xx - dy * dy + dp[i], cnt[ii] + 1); } else return make_pair(dp[n], cnt[ii] + 1); } return {-1, -1}; } 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(v.size() && v.back().first == x) 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, ans = -1e18; while(l < r){ mid = (l + r) / 2; auto p = go(mid); ans = max(ans, p.first - k * mid); if(p.second <= k) r = mid; else l = mid + 1; } return ans; } /* 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; } */

Compilation message (stderr)

aliens.cpp: In function 'std::pair<long long int, long long int> go(ll)':
aliens.cpp:37:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   37 |     auto&[x, y] = v[0];
      |          ^
aliens.cpp:40:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   40 |         auto&[x, y] = v[i - 1];
      |              ^
aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:60:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   60 |     for(auto& [x, y] : tmp){
      |               ^
#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...