Submission #624210

#TimeUsernameProblemLanguageResultExecution timeMemory
624210bruceccccccAliens (IOI16_aliens)C++14
0 / 100
0 ms212 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; #define intersectX(a, b) (b.c - a.c) / (double) (a.m - b.m) struct Photo { int x, s; }; struct Line { ll m, c; }; // double intersectX(Line& a, Line& b) { // return (b.c - a.c) / (double) (a.m - b.m); // } ll take_photos(int n, int m, int k, vector<int> r, vector<int> c) { vector<int> size(m, 0); for (int i = 0; i < n; i++) { if (r[i] <= c[i]) size[r[i]] = max(size[r[i]], c[i] - r[i] + 1); else size[c[i]] = max(size[c[i]], r[i] - c[i] + 1); } vector<Photo> photos; vector<ll> add(1), st(1); int prev = 0; for (int i = 0; i < m; i++) { if (size[i] > prev) { prev = size[i]; if (photos.empty() || i >= photos.back().x + photos.back().s) { st.push_back(0); add.push_back(add.back() + 1ll * size[i] * size[i]); } else { ll start = photos.back().x + photos.back().s - i; add.push_back(add.back() + 1ll * size[i] * size[i] - start * start); st.push_back(start * start); } photos.push_back({ i, size[i] }); } prev = max(0, prev - 1); } ll ans = add[photos.size()]; vector<deque<Line>> hulls(k+1); for (int i = 0; i < photos.size(); i++) { for (int j = k; j >= 1; j--) { auto& d = hulls[j-1]; ll a; ll endPoint = photos[i].x + photos[i].s; if (j > 1 && d.size() > 0) { int l = 0, r = d.size() - 1; while (d.size() > 1 && intersectX(d[0], d[1]) <= endPoint) d.pop_front(); Line& val = d[0]; a = val.m * endPoint + val.c + 1ll * endPoint * endPoint - add[i+1]; } else if (j == 1) { ll w = endPoint - photos.front().x; a = w * w - add[i+1]; } if (i == photos.size() - 1 && j == k) { ans += a; break; } auto& q = hulls[j]; Line next = { -2 * photos[i+1].x, 1ll * photos[i+1].x * photos[i+1].x - st[i+2] + add[i+1] + a }; int s = q.size() - 1; while (s >= 1 && intersectX(next, q[s-1]) < intersectX(q[s-1], q[s])) { q.pop_back(); s--; } q.push_back(next); } } return ans; }

Compilation message (stderr)

aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:49:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Photo>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |   for (int i = 0; i < photos.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~
aliens.cpp:55:13: warning: unused variable 'l' [-Wunused-variable]
   55 |         int l = 0, r = d.size() - 1;
      |             ^
aliens.cpp:55:20: warning: unused variable 'r' [-Wunused-variable]
   55 |         int l = 0, r = d.size() - 1;
      |                    ^
aliens.cpp:67:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Photo>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |       if (i == photos.size() - 1 && j == k) {
      |           ~~^~~~~~~~~~~~~~~~~~~~
aliens.cpp:68:13: warning: 'a' may be used uninitialized in this function [-Wmaybe-uninitialized]
   68 |         ans += a;
      |         ~~~~^~~~
#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...