Submission #562934

#TimeUsernameProblemLanguageResultExecution timeMemory
562934hoanghq2004Aliens (IOI16_aliens)C++17
100 / 100
203 ms9624 KiB
#include <bits/stdc++.h> #pragma GCC optimize ("O3") #pragma GCC optimize ("unroll-loops") #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "aliens.h" using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 1e5 + 10; struct Line { long long a, b; int t; long long operator() (long long x) { return a * x + b; } }; vector <Line> convex; int pointer; int bad(const Line &L1, const Line &L2, const Line &L3) { return 1.0L * (L2.b - L1.b) * (L1.a - L3.a) >= 1.0L * (L3.b - L1.b) * (L1.a - L2.a); } void add(Line L) { while (convex.size() >= 2 && bad(convex.end()[-2], convex.back(), L)) convex.pop_back(); convex.push_back(L); pointer = min(pointer, (int)convex.size() - 1); } pair <long long, int> get(long long x) { if (convex.empty()) return {1e18, 0}; while (pointer < convex.size() - 1 && convex[pointer](x) > convex[pointer + 1](x)) ++pointer; return {convex[pointer](x), convex[pointer].t}; } vector <pair <int, int> > P, Q; pair <long long, int> f[N]; pair <long long, int> calc(long long C) { convex.clear(), pointer = 0; for (int i = 0; i < P.size(); ++i) { f[i] = {1LL * (P[i].second - P[0].first + 1) * (P[i].second - P[0].first + 1) + C, 1}; pair <long long, int> cur = get(2 * (P[i].second + 1)); cur.first += 1LL * (P[i].second + 1) * (P[i].second + 1) + C; ++cur.second; assert(f[i].first >= 0); f[i] = min(f[i], cur); if (i + 1 < P.size()) { long long delta = 0; if (P[i + 1].first <= P[i].second) { delta = 1LL * (P[i].second - P[i + 1].first + 1) * (P[i].second - P[i + 1].first + 1); } add({- P[i + 1].first, (1LL * P[i + 1].first * P[i + 1].first) - delta + f[i].first, f[i].second}); } } return f[P.size() - 1]; } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { for (int i = 0; i < n; ++i) { if (r[i] > c[i]) swap(r[i], c[i]); P.push_back({r[i], - c[i]}); } sort(P.begin(), P.end()); for (auto &[x, y]: P) y = - y; for (auto [x, y]: P) { if (Q.size() && y <= Q.back().second) continue; Q.push_back({x, y}); } swap(P, Q); if (calc(0).second <= k) return calc(0).first; long long L = 0, R = 1e13; while (L < R) { long long mid = L + R >> 1; if (calc(mid).second <= k) R = mid; else L = mid + 1; } return calc(L).first - L * k; } //int main() { // int n, m, k; // assert(3 == scanf("%d %d %d", &n, &m, &k)); // std::vector<int> r(n), c(n); // for (int i = 0; i < n; i++) { // assert(2 == scanf("%d %d", &r[i], &c[i])); // } // long long ans = take_photos(n, m, k, r, c); // // // printf("%lld\n", ans); // return 0; //}

Compilation message (stderr)

aliens.cpp: In function 'std::pair<long long int, int> get(long long int)':
aliens.cpp:38:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     while (pointer < convex.size() - 1 && convex[pointer](x) > convex[pointer + 1](x)) ++pointer;
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~
aliens.cpp: In function 'std::pair<long long int, int> calc(long long int)':
aliens.cpp:46:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i = 0; i < P.size(); ++i) {
      |                     ~~^~~~~~~~~~
aliens.cpp:53:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         if (i + 1 < P.size()) {
      |             ~~~~~~^~~~~~~~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:79:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |         long long mid = L + R >> 1;
      |                         ~~^~~
#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...