Submission #957284

#TimeUsernameProblemLanguageResultExecution timeMemory
957284duckindogAliens (IOI16_aliens)C++17
0 / 100
5 ms1372 KiB
#include <bits/stdc++.h> using namespace std; #ifndef LOCAL #include "aliens.h" #endif struct Line { long long a, b; double x(const auto& rhs) { return 1.0 * (rhs.b - b) / (a - rhs.a); }; }; long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) { using pii = pair<int, int>; vector<pii> p(n); for (int i = 0; i < n; ++i) { if (r[i] > c[i]) swap(r[i], c[i]); p[i] = {r[i], c[i]}; } auto dis = [&](pii a) { return abs(a.first - a.second) + 1; }; p.push_back({-1, -1}); vector<vector<long long>> f(k + 1, vector<long long>(n + 1, 1e15)); sort(p.begin(), p.end(), [&](const auto& a, const auto& b) { return a.first < b.first; }); f[0][0] = 0; for (int i = 1; i <= k; ++i) { vector<Line> hull; for (int j = 1; j <= n; ++j) { long long pl = -p[j].first + 1; long long pre = max(0ll, p[j - 1].second + pl); pre *= pre; Line line = {2 * pl, f[i - 1][j - 1] + pl * pl - pre}; while (hull.size() > 1 && hull.end()[-2].x(hull.end()[-1]) > hull.end()[-2].x(line)) hull.pop_back(); hull.push_back(line); auto cal = [&](int it) { const auto& [a, b] = hull[it]; long long x = p[j].second; return a * x + b + x * x; }; int l = 0, r = hull.size() - 2, it = 0; while (l <= r) { int mid = l + r >> 1; if (cal(mid) >= cal(mid + 1)) l = it = mid + 1; else r = mid - 1; } f[i][j] = cal(it); } } return f[k][n]; } #ifdef LOCAL int32_t main() { cin.tie(0)->sync_with_stdio(0); // freopen("output.txt", "w", stdout); int n, m, k; cin >> n >> m >> k; vector<int> r(n), c(n); for (int i = 0; i < n; ++i) cin >> r[i] >> c[i]; cout << take_photos(n, m, k, r, c) << "\n"; } #endif

Compilation message (stderr)

aliens.cpp:11:18: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   11 |   double x(const auto& rhs) { return 1.0 * (rhs.b - b) / (a - rhs.a); };
      |                  ^~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |         int mid = l + r >> 1;
      |                   ~~^~~
aliens.cpp:23:8: warning: variable 'dis' set but not used [-Wunused-but-set-variable]
   23 |   auto dis = [&](pii a) { return abs(a.first - a.second) + 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...