Submission #380549

#TimeUsernameProblemLanguageResultExecution timeMemory
380549hoaphat1Aliens (IOI16_aliens)C++17
0 / 100
1 ms364 KiB
#include <bits/stdc++.h> using namespace std; long long take_photos(int n, int m, int k, vector<int> r, vector<int> c) { vector<pair<int,int>> a; for (int i = 0; i < n; i++) { if (r[i] < c[i]) swap(r[i], c[i]); a.emplace_back(r[i], c[i]); } sort(a.begin(), a.end()); vector<pair<int,int>> b; for (int i = 0; i < n; i++) { while (!b.empty() && b.back().second >= a[i].second) b.pop_back(); b.push_back(a[i]); } swap(a, b); n = (int) a.size(); auto test = [&](long long c) { const long long inf = 1e18; vector<pair<long long, int>> dp(n + 1, make_pair(inf, 0)); dp[0] = {0, 0}; for (int j = 1; j <= n; j++) { for (int from = j; from > 0; from--) { long long pre = (from > 1 ? a[from - 2].first : 0); if (pre >= a[from - 1].second) pre = (pre - a[from - 1].second + 1) * (pre - a[from - 1].second + 1); else pre = 0; dp[j] = min(dp[j], {dp[from - 1].first + 1ll * (a[j - 1].first - a[from - 1].second + 1) * (a[j - 1].first - a[from - 1].second + 1) + c - pre, dp[from - 1].second + 1}); } } return dp[n]; }; long long l = 0, R = 1ll * m * m, ans = -1; while (l <= R) { long long mid = l + R >> 1; if (test(mid).second <= k) { ans = mid; R = mid - 1; } else l = mid + 1; } assert(ans !=- 1); return test(ans).first - ans * k; } /* int main() { ios::sync_with_stdio(false); cin.tie(0); cout << take_photos(2, 6, 2, {2, 3}, {3, 4}); }*/

Compilation message (stderr)

aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:35:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |   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...