Submission #474268

#TimeUsernameProblemLanguageResultExecution timeMemory
474268evenharderAliens (IOI16_aliens)C++14
Compilation error
0 ms0 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;} }; 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(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; vector<int> pre; ConvexHull() { } void insert(line p) { while(1) { size_t sz = v.size(); if(sz >= 2 && check_back(v[sz-2], v[sz-1], p)) { v.pop_back(); sz--; } else break; } v.push_back(p); } ll query(ll x) { while(1) { size_t sz = v.size(); if(sz - apos >= 2 && check_front(x, v[apos], v[apos+1])) apos++; else break; } if(v[apos].i == v.back().i || v[apos].i == 0) pre.push_back(1); else pre.push_back(pre[v[apos].i-1] + 1); return v[apos].calc(x); } }; pll take_photos_lambda(vector<pii>& v1, ll eff) { ConvexHull ch; ll val = 0; ch.insert(line(0, 3e11)); ch.pre.push_back(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), i+1 }); val = ch.query(v1[i].first) + v1[i].first * v1[i].first + eff; } return pll{val, ch.pre.back()}; } ll take_photos(int n, int m, int k, int* r, 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<n;i++) { if(!v1.empty() && v1.back().first == v[i].first) { continue; } if(!v1.empty() && v1.back().second >= v[i].second) { v1.pop_back(); } v1.push_back(v[i]); } ll leff = 0, reff = 1LL*m*m; int lind = v1.size(), rind = 1; // decreases when leff increase while(leff < reff) { 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 + 1; } else { rind = res.second; reff = meff - 1; } } return take_photos_lambda(v1, leff).first - k * leff; }

Compilation message (stderr)

aliens.cpp: In function 'pll take_photos_lambda(std::vector<std::pair<int, int> >&, ll)':
aliens.cpp:56: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]
   56 |     for(int i=0;i<v1.size();i++) {
      |                 ~^~~~~~~~~~
/usr/bin/ld: /tmp/ccX4QnRZ.o: in function `main':
grader.cpp:(.text.startup+0xf0): undefined reference to `take_photos(int, int, int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status