Submission #435845

#TimeUsernameProblemLanguageResultExecution timeMemory
435845HegdahlAliens (IOI16_aliens)C++17
25 / 100
2067 ms6988 KiB
#include <bits/stdc++.h> #include "aliens.h" #define ar array using namespace std; using ll = long long; int n, m, k; vector<ar<ll, 2>> a; const ll INF = 1LL<<60; ll sq(ll a) { return a*a; } void minset(ll &p, ll v) { if (v < p) p = v; } ll solve() { vector<vector<ll>> dp(n+1, vector<ll>(k+1, INF)); dp[0][0] = 0; for (int kk = 0; kk < k; ++kk) { for (int i = 0; i < n; ++i) { int pr = i==0 ? -1 : a[i-1][1]; int l = a[i][0], r = a[i][1]; for (int j = i+1; j <= n; ++j) { r = a[j-1][1]; minset(dp[j][kk+1], dp[i][kk] + sq(r-l+1) - sq(max(0, pr-l+1))); } } } return *min_element(dp[n].begin(), dp[n].end()); } ll take_photos(int n_, int m_, int k_, vector<int> r_, vector<int> c_) { n = n_, m = m_, k = k_; a.resize(n); for (int i = 0; i < n; ++i) a[i] = {min(r_[i], c_[i]), max(r_[i], c_[i])}; sort(a.begin(), a.end(), [&](auto p0, auto p1) { if (p0[0] != p1[0]) return p0[0] < p1[0]; return p0[1] > p1[1]; }); { decltype(a) na; int mxr = -1e9; for (int i = 0; i < n; ++i) { if (a[i][1] > mxr) { mxr = a[i][1]; na.push_back(a[i]); } } a = move(na); n = (int)a.size(); } return solve(); }
#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...