Submission #45972

#TimeUsernameProblemLanguageResultExecution timeMemory
45972RezwanArefin01Aliens (IOI16_aliens)C++17
25 / 100
2047 ms7668 KiB
#include <bits/stdc++.h> #include "aliens.h" using namespace std; typedef long long ll; typedef pair<int, int> ii; #define sq(a) ((ll)(a) * (a)) #define cost(j, i) (sq(r[i] - l[j + 1] + 1) - sq(max(0, r[j] - l[j + 1] + 1))) ll take_photos(int n, int m, int K, vector<int> R, vector<int> C) { vector<ii> tmp; for(int i = 0; i < n; i++) { if(R[i] > C[i]) swap(R[i], C[i]); tmp.emplace_back(C[i], R[i]); } sort(tmp.begin(), tmp.end()); tmp.erase(unique(tmp.begin(), tmp.end()), tmp.end()); vector<int> l = {-1}, r = {-1}; for(ii seg : tmp) { if(seg.first == r.back()) continue; while(l.size() && seg.second <= l.back() && r.back() <= seg.first) r.pop_back(), l.pop_back(); l.push_back(seg.second); r.push_back(seg.first); } n = l.size() - 1; ll dp[K + 1][n + 1]; memset(dp, 63, sizeof dp); for(int i = 1; i <= n; i++) dp[1][i] = sq(r[i] - l[1] + 1); for(int k = 2; k <= K; k++) { for(int i = 1; i <= n; i++) { for(int j = 1; j < i; j++) { dp[k][i] = min(dp[k][i], dp[k - 1][j] + sq(r[i] - l[j + 1] + 1) - sq(max(0, r[j] - l[j + 1] + 1)) ); } } } ll ret = 1e18; for(int i = 1; i <= K; i++) ret = min(ret, dp[i][n]); return ret; } #ifdef LOCAL_TESTING int main() { freopen("in", "r", stdin); int n, m, k; assert(3 == scanf("%d %d %d", &n, &m, &k)); std::vector<int> r(n), c(n); for (int i = 0; i < n; i++) { assert(2 == scanf("%d %d", &r[i], &c[i])); } ll ans = take_photos(n, m, k, r, c); printf("%lld\n", ans); return 0; } #endif
#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...