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>
#include<vector>
using namespace std;
int rr[300005];
int cc[300005];
int color[305][305];
long long int dp[5005][5005];
bool can[500005];
struct node
{
long long int r;
long long int c;
}nod[500005];
int nowr[300005];
int nowc[300005];
bool cmp(node x,node y)
{
if(x.r == y.r)return x.c < y.c;
else return x.r < y.r;
}
double getk(int num1,int num2,int tim)
{
long long int x1 = nod[num1+1].r;
long long int x2 = nod[num2+1].r;
long long int zz = 0;
long long int y1 = dp[num1][tim-1] + (nod[num1+1].r) * (nod[num1+1].r) - max(zz,nod[num1].c - nod[num1+1].r + 1) * max(zz,nod[num1].c - nod[num1+1].r + 1);
long long int y2 = dp[num2][tim-1] + (nod[num2+1].r) * (nod[num2+1].r) - max(zz,nod[num2].c - nod[num2+1].r + 1) * max(zz,nod[num2].c - nod[num2+1].r + 1);
if(x1 == x2)
{
return 1.0 * (y1-y2) / 1e-9;
}
else
{
return 1.0 * (y1-y2) / (x1-x2);
}
}
int q[300005];
long long take_photos(int n, int m, int k, std::vector<int> r, std::vector<int> c) {
for(int i=0;i<r.size();i++)rr[i+1] = r[i];
for(int i=0;i<c.size();i++)cc[i+1] = c[i];
bool flag2 = true;
for(int i=1;i<=n;i++)
{
if(rr[i] > cc[i])swap(rr[i],cc[i]);
if(rr[i] != cc[i])flag2 = false;
}
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)dp[i][j] = 1e18;
dp[i][0] = 1e18;
}
dp[0][0] = 0;
for(int i=1;i<=n;i++)
{
nod[i].r = rr[i];
nod[i].c = cc[i];
}
nod[0].r = -10000;
nod[0].c = -10000;
for(int i=1;i<=n;i++)can[i] = true;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
if(rr[i] <= rr[j] && cc[j] <= cc[i] && i!=j && (rr[i] != rr[j] || cc[i] != cc[j]))can[j] = false;
}
}
int num = 0;
for(int i=1;i<=n;i++)
{
if(can[i] == false)continue;
num++;
nod[num].c = cc[i];
nod[num].r = rr[i];
}
sort(nod+1,nod+num+1,cmp);
for(int i=1;i<=num;i++)
{
dp[i][1] = (nod[i].c + 1) * (nod[i].c + 1);
}
for(int tim=1;tim<=k;tim++)
{
int h = 1;
int t = 0;
for(int i=1;i<=num;i++)
{
while(h < t && getk(i-1,q[t],tim) <= getk(q[t],q[t-1],tim))t--;
q[++t] = i-1;
while(h < t && (getk(q[h+1],q[h],tim) <= 2 * (nod[i].c+1)))h++;
int j = q[h];
long long int zero = 0;
long long int del = nod[j].c - nod[j+1].r + 1;
long long int sub = max(zero,del) * max(zero,del);
long long int add = (nod[i].c - nod[j+1].r + 1) * (nod[i].c - nod[j+1].r + 1);
// cout<<tim<<" "<<i<<" "<<j<<endl;
dp[i][tim] = dp[j][tim-1] + add - sub;
}
}
//cout<<getk(1,0,2)<<" "<<getk(0,0,2)<<endl;
long long int ans = 1e18;
for(int i=1;i<=k;i++)ans = min(ans,dp[num][i]);
return ans;
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:40:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
40 | for(int i=0;i<r.size();i++)rr[i+1] = r[i];
| ~^~~~~~~~~
aliens.cpp:41:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
41 | for(int i=0;i<c.size();i++)cc[i+1] = c[i];
| ~^~~~~~~~~
aliens.cpp:42:7: warning: variable 'flag2' set but not used [-Wunused-but-set-variable]
42 | bool flag2 = true;
| ^~~~~
# | 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... |