# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1022074 | vjudge1 | Aliens (IOI16_aliens) | C++17 | 1 ms | 1116 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 <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 4e3 + 100;
int a[maxn];
int b[maxn];
int c[maxn];
int pref[maxn];
int suf[maxn];
ll dp[maxn][maxn];
vector<int> v;
int get(int i, int j){
if(!i) return 0;
ll x = max(0, (- i + a[i] + j + a[j]) / 2);
return x * x;
}
void calc(int cnt, int l = 1, int r = v.size(), int tl = 1, int tr = v.size()){
int i = (l + r) >> 1, tm;
for(int j = tl; j <= min(i, tr); j++){
ll x = dp[j-1][cnt-1] + get(v[j-1], v[i-1]);
if(j > 1) x -= get(v[j-1], v[j-2]);
if(dp[i][cnt] > x){
dp[i][cnt] = x;
tm = j;
}
}
if(l < r){
calc(cnt, l, i, tl, tm);
calc(cnt, i+1, r, tm, tr);
}
}
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c){
for(int i = 0; i < n; i++){
r[i]++; c[i]++;
int x = r[i] + c[i] - 1;
a[x] = max(a[x], abs(r[i] - c[i]) + 1);
}
for(int i = 1; i < m * 2; i++){
pref[i] = max(pref[i-1] - 1, a[i]);
}
for(int i = m * 2 - 1; i > 0; i--){
suf[i] = max(suf[i+1] - 1, a[i]);
}
for(int i = 1; i < m * 2; i++){
if(max(pref[i-1], suf[i+1]) <= a[i] && a[i]){
v.push_back(i);
}
}
for(int i = 0; i <= v.size(); i++){
fill(dp[i], dp[i] + k + 1, (ll)1e18);
}
dp[0][0] = 0;
for(int cnt = 1; cnt <= k; cnt++){
calc(cnt);
}
return *min_element(dp[v.size()], dp[v.size()] + k + 1);
}
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... |