# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
124875 | nvmdava | Aliens (IOI16_aliens) | C++17 | 2045 ms | 6376 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > v, t;
long long dp[2][100005];
long long cost(int l, int r){
l++;
if(l > r) return 0;
long long t1 = v[r].second - v[l].first;
long long t2 = max(0, v[l - 1].second - v[l].first);
return t1 * t1 - t2 * t2;
}
void opt(int id, int l, int r, int optl, int optr){
if(l > r) return;
int m = (l + r) >> 1;
dp[id][m] = 0x3f3f3f3f3f3f3f3f;
int optm;
for(int o = optl; o <= min(m, optr); o++){
long long c = cost(o, m);
if(dp[id][m] >= dp[id ^ 1][o] + c){
dp[id][m] = dp[id ^ 1][o] + c;
optm = o;
}
}
opt(id, l, m - 1, optl, optm);
opt(id, m + 1, r, optm, optr);
}
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c){
for(int i = 0; i < n; i++)
t.push_back({min(r[i], c[i]), max(c[i], r[i]) + 1});
sort(t.begin(), t.end());
int mx = -1;
v.push_back({-1, -1});
for(auto& x : t)
if(x.second > mx)
v.push_back({x.first, mx = x.second});
n = v.size() - 1;
k = min(k, n);
memset(dp, 0x3f3f, sizeof dp);
dp[0][0] = 0;
for(int i = 1; i <= k; i++){
opt(i & 1, 0, n, 0, n);
}
return dp[k & 1][n];
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |