Submission #562707

#TimeUsernameProblemLanguageResultExecution timeMemory
562707hoanghq2004Aliens (IOI16_aliens)C++14
25 / 100
6 ms4308 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 = 4010; long long f[N][N]; struct Line { long long a, b; long long operator() (int 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 - L2.a) >= 1.0L * (L3.b - L1.b) / (L1.a - L3.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); } long long get(int x) { if (convex.empty()) return 1e18; while (pointer < convex.size() - 1 && convex[pointer](x) > convex[pointer + 1](x)) ++pointer; return convex[pointer](x); } long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { vector <pair <int, int> > P, Q; 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); for (int i = 0; i < P.size(); ++i) { f[i][1] = 1LL * (P[i].second - P[0].first + 1) * (P[i].second - P[0].first + 1); } for (int j = 2; j <= k; ++j) { convex.clear(); pointer = 0; for (int i = 0; i < P.size(); ++i) { f[i][j] = f[i][j - 1]; f[i][j] = min(f[i][j], get(2 * (P[i].second + 1)) + ((P[i].second + 1) * (P[i].second + 1))); 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, (P[i + 1].first * P[i + 1].first) - delta + f[i][j - 1]}); } } } return f[P.size() - 1][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 'long long int get(int)':
aliens.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Line>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |     while (pointer < convex.size() - 1 && convex[pointer](x) > convex[pointer + 1](x)) ++pointer;
      |            ~~~~~~~~^~~~~~~~~~~~~~~~~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:50:16: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |     for (auto &[x, y]: P) y = - y;
      |                ^
aliens.cpp:51:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   51 |     for (auto [x, y]: P) {
      |               ^
aliens.cpp:56: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]
   56 |     for (int i = 0; i < P.size(); ++i) {
      |                     ~~^~~~~~~~~~
aliens.cpp:62:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |         for (int i = 0; i < P.size(); ++i) {
      |                         ~~^~~~~~~~~~
aliens.cpp:65: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]
   65 |             if (i + 1 < P.size()) {
      |                 ~~~~~~^~~~~~~~~~
#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...