Submission #749849

#TimeUsernameProblemLanguageResultExecution timeMemory
749849Desh03Aliens (IOI16_aliens)C++17
Compilation error
0 ms0 KiB
#include "aliens.h" #include <bits/stdc++.h> using namespace std; const long long INF = 1e18; struct point { int x, y; bool operator < (const point &p) const { return x == p.x ? y < p.y : x < p.x; } }; vector<point> r; vector<long long> dp, ndp; long long cost(int i, int j) { long long ext = (r[i].x <= r[i - 1].y ? (long long) (r[i - 1].y - r[i].x + 1) * (r[i - 1].y - r[i].x + 1) : 0); return (long long) (r[j].y - r[i].x + 1) * (r[j].y - r[i].x + 1) - ext; } void dnc(int i, int l, int r, int optl, int optr) { if (l > r) return; int mid = l + r >> 1, opt; long long w = INF; for (int k = optl; k <= min(mid, optr + 1); k++) { long long c = cost(k + 1, mid); if (w > dp[k] + c) w = dp[k] + c, opt = k; } ndp[mid] = w; dnc(i, l, mid - 1, optl, opt); dnc(i, mid + 1, r, opt, optr); } long long take_photos(int n, int m, int k, vector<int> R, vector<int> C) { vector<point> f; r = vector<point> (); for (int i = 0; i < n; i++) { if (R[i] > C[i]) swap(R[i], C[i]); f.push_back({R[i], C[i]}); } sort(f.begin(), f.end()); r.push_back(f[0]); for (int i = 1; i < n; i++) { if (r.back().x == f[i].x) { r.pop_back(); r.push_back(f[i]); } else if (f[i].y > r.back().y) { r.push_back(f[i]); } } n = r.size(); dp = vector<long long> (n), ndp = dp; for (int i = 0; i < n; i++) dp[i] = (long long) (r[i].y - r[0].x + 1) * (r[i].y - r[0].x + 1); for (int i = 1; i < k; i++) dnc(i, i, n - 1, 0, n - 2), dp = ndp; long long ans = INF; for (int i = 0; i < k; i++) ans = min(ans, dp[i][n - 1]); return ans; }

Compilation message (stderr)

aliens.cpp: In function 'void dnc(int, int, int, int, int)':
aliens.cpp:24:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   24 |     int mid = l + r >> 1, opt;
      |               ~~^~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:58:53: error: invalid types '__gnu_cxx::__alloc_traits<std::allocator<long long int>, long long int>::value_type {aka long long int}[int]' for array subscript
   58 |     for (int i = 0; i < k; i++) ans = min(ans, dp[i][n - 1]);
      |                                                     ^