Submission #474375

#TimeUsernameProblemLanguageResultExecution timeMemory
474375evenharderAliens (IOI16_aliens)C++14
100 / 100
192 ms10188 KiB
#include <iostream> #include <algorithm> #include <numeric> #include <utility> #include <vector> using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; struct line { ll a, b, i; line(ll a=0, ll b=0, ll i=0) : a(a), b(b), i(i) {} ll calc(ll x) { return a*x+b;} double inter(line l) { return double(l.b - b) / (a - l.a); } }; bool check_back_pd(line& p0, line& p1, line& p2) { return p0.inter(p1) > p1.inter(p2); } bool check_back(line& p0, line& p1, line& p2) { return (p1.b - p0.b) * (p1.a - p2.a) >= (p0.a - p1.a) * (p2.b - p1.b); } bool check_front_pd(ll x, line& p0, line& p1) { return x > p0.inter(p1); } bool check_front(ll x, line& p0, line& p1) { return x * (p0.a - p1.a) >= (p1.b - p0.b); } struct ConvexHull { size_t apos = 0; vector<line> v; void insert(line p) { while(1) { size_t sz = v.size(); if(sz - apos >= 2 && check_back_pd(v[sz-2], v[sz-1], p)) { v.pop_back(); sz--; } else break; } v.push_back(p); } pll query(ll x) { while(1) { size_t sz = v.size(); if(sz - apos >= 2 && check_front_pd(x, v[apos], v[apos+1])) apos++; else break; } return pll{v[apos].calc(x), v[apos].i}; } }; pll take_photos_lambda(vector<pii>& v1, ll eff) { ConvexHull ch; ll val = 0; ll cnt = 0; for(int i=0;i<v1.size();i++) { ch.insert(line{-2LL * (v1[i].second-1), val + 1LL * (v1[i].second-1) * (v1[i].second-1) - (i && v1[i-1].first >= v1[i].second ? 1LL * (v1[i-1].first - v1[i].second + 1) * (v1[i-1].first - v1[i].second + 1) : 0), cnt }); pll res = ch.query(v1[i].first); val = res.first + 1LL * v1[i].first * v1[i].first + eff; cnt = res.second + 1; } return pll{val, cnt}; } ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) { vector<pii> v(n), v1; for(int i=0;i<n;i++) { v[i] = pii{max(c[i], r[i]), min(c[i], r[i])}; } sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); for(int i=0;i<v.size();i++) { if(!v1.empty() && v1.back().first == v[i].first) { continue; } while(!v1.empty() && v1.back().second >= v[i].second) { v1.pop_back(); } v1.push_back(v[i]); } k = min(k, (int)v1.size()); ll leff = 0, reff = 1LL*m*m; int lind = v1.size(), rind = 1; // decreases when leff increase while(reff - leff >= 2) { ll meff = (leff + reff) / 2; pll res = take_photos_lambda(v1, meff); if(res.second < rind) res.second = rind; if(res.second > lind) res.second = lind; if(res.second == k) { return res.first - k * meff; } else if(res.second > k) { lind = res.second; leff = meff; } else { rind = res.second; reff = meff; } } // answer is max(take_photos_lambda().first - k * eff) for all eff when minimizing answer return max(take_photos_lambda(v1, leff).first - k * leff, take_photos_lambda(v1, reff).first - k * reff); }

Compilation message (stderr)

aliens.cpp: In function 'pll take_photos_lambda(std::vector<std::pair<int, int> >&, ll)':
aliens.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i=0;i<v1.size();i++) {
      |                 ~^~~~~~~~~~
aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |     for(int i=0;i<v.size();i++) {
      |                 ~^~~~~~~~~
#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...