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 <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<int> R, C;
vector<long long> a(1), b(1);
long long sq(long long x)
{
return x*x;
}
const long long INF = 1'000'000'000'000'000'001;
long long take_photos(int n, int m, int k, vector<int> r, vector<int> c)
{
R = r;
C = c;
int I[n];
for(int i = 0; i < n; i++)
I[i] = i;
sort(I, I+n, [] (int x, int y)
{
if(min(R[x], C[x]) == min(R[y], C[y]))
return max(R[x], C[x]) > max(R[y], C[y]);
return min(R[x], C[x]) < min(R[y], C[y]);
});
int maxb = -1;
for(int i:I)
{
if(maxb < max(r[i], c[i]))
{
maxb = max(r[i], c[i]);
a.push_back(min(r[i], c[i]));
b.push_back(max(r[i], c[i]));
}
}
n = a.size() - 1;
k = min(k, n);
long long low = 0;
long long high = (long long)m * m;
a[0] = b[0] = -1;
while (low <= high) {
long long ct = (low + high) / 2;
long long dp[n+1];
int photos[n+1];
dp[0] = photos[0] = 0;
for(int i = 1; i <= n; i++)
{
dp[i] = INF;
photos[i] = i+1;
for(int j = 0; j < i; j++)
{
long long addition = -sq(b[j]-a[j+1]+1);
if (b[j] - a[j+1] + 1 <= 0)
addition = 0;
addition += ct + dp[j];
long long val = sq(b[i]-a[j+1]+1) + addition;
if (val == dp[i]) photos[i] = min(photos[i], photos[j] + 1);
else if(val < dp[i])
{
photos[i] = photos[j] + 1;
dp[i] = val;
}
}
}
if(low == high) return dp[n] - ct*k;
else
{
if(photos[n] <= k) high = ct;
else low = ct+1;
}
}
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:90:1: warning: control reaches end of non-void function [-Wreturn-type]
90 | }
| ^
# | 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... |