Submission #1046828

#TimeUsernameProblemLanguageResultExecution timeMemory
1046828Gromp15Aliens (IOI16_aliens)C++17
41 / 100
2001 ms3792 KiB
#include "aliens.h" #include <bits/stdc++.h> #define ar array #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define ll long long using namespace std; template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } const ll INF = 1e18; long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) { vector<ar<int, 2>> a(n); for (int i = 0; i < n; i++) { a[i] = {r[i], c[i]}; if (r[i] > c[i]) swap(a[i][0], a[i][1]); } sort(all(a)); int mx = -1; vector<ar<int, 2>> b; for (int i = 0; i < n; i++) { int r = i; while (r+1 < n && a[r+1][0] == a[r][0]) r++; if (a[r][1] > mx) { b.push_back({a[r][0], a[r][1]}); mx = a[r][1]; } } swap(a, b); n = sz(a); ll L = 0, R = 1e13, ans = -1; while (L <= R) { ll mid = (L+R)/2; vector<ar<ll, 3>> dp(n+1, {INF, INF, -INF}); dp[0] = {0, 0, 0}; auto sq = [&](int x) { return (ll)x * x; }; for (int i = 1; i <= n; i++) { for (int j = i-1; j >= 0; j--) { ll nc = dp[j][0] + sq(a[i-1][1] - a[j][0] + 1) - (j ? sq(max(0, a[j-1][1] - a[j][0] + 1)) : 0) + mid; if (ckmin(dp[i][0], nc)) { dp[i][1] = dp[j][1] + 1; dp[i][2] = dp[j][2] + 1; } else if (dp[i][0] == nc) { ckmin(dp[i][1], dp[j][1] + 1); ckmax(dp[i][2], dp[j][2] + 1); } } } if (dp[n][1] <= k) { int u = min(k, int(dp[n][2])); ans = dp[n][0] - u * mid; R = mid-1; } else L = mid+1; } return ans; }
#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...