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];
int dp[1005][1005];
bool can[500005];
struct node
{
int r;
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;
}
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] = 1e9;
dp[i][0] = 1e9;
}
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;
if(k == n && m <= 100)
{
for(int i=1;i<=n;i++)
{
for(int j=min(rr[i],cc[i]);j<=max(rr[i],cc[i]);j++)for(int k=min(rr[i],cc[i]);k<=max(rr[i],cc[i]);k++)color[j][k] = 1;
}
int cnt = 0;
for(int i=0;i<=m-1;i++)for(int j=0;j<=m-1;j++)if(color[i][j] == 1)cnt++;
return cnt;
}
/*if(flag2 == true)
{
sort(nod+1,nod+n+1,cmp);
for(int i=1;i<=n;i++)
{
for(int j=1;j<=k;j++)for(int pre=0;pre<=i-1;pre++)dp[i][j] = min(dp[i][j],dp[pre][j-1] + (nod[i].r-nod[pre+1].r + 1) * (nod[i].r-nod[pre+1].r + 1));
}
int ans = 1e9;
for(int i=1;i<=k;i++)ans = min(ans,dp[n][i]);
return ans;
} */
if(n <= 500 && m <= 1000)
{
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);
/*cout<<num<<endl;
cout<<endl;
for(int i=1;i<=num;i++)
{
cout<<nod[i].r<<" "<<nod[i].c<<endl;
}
cout<<endl;*/
for(int i=1;i<=num;i++)
{
for(int j=1;j<=k;j++)
{
for(int pre=0;pre<=i-1;pre++)
{
int del = nod[pre].c - nod[pre+1].r + 1;
int sub = max(0,del) * max(0,del);
int add = (nod[i].c - nod[pre+1].r + 1) * (nod[i].c - nod[pre+1].r + 1);
dp[i][j] = min(dp[i][j],dp[pre][j-1] + add - sub);
}
}
}
/*for(int i=1;i<=num;i++)
{
for(int j=1;j<=k;j++)cout<<dp[i][j]<<" ";
cout<<endl;
}*/
int ans = 1e9;
for(int i=1;i<=k;i++)ans = min(ans,dp[num][i]);
return ans;
}
return 0;
}
Compilation message (stderr)
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:23:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i=0;i<r.size();i++)rr[i+1] = r[i];
| ~^~~~~~~~~
aliens.cpp:24:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=0;i<c.size();i++)cc[i+1] = c[i];
| ~^~~~~~~~~
aliens.cpp:25:7: warning: variable 'flag2' set but not used [-Wunused-but-set-variable]
25 | 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... |