이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <iostream>
#include <algorithm>
using namespace std;
struct node{
long long int x,y;
}a[1000005];
long long int dp[400005],x[1000005],y[1000005],t[1000005][3],g[100005];
bool cmp(node a,node b)
{
if(a.x<b.x)return 1;
if(a.x>b.x)return 0;
if(a.y<a.y)return 1;
return 0;
}
double check(long long int a,long long int b)
{
return (t[a][0]-t[b][0])/(t[a][1]-t[b][1]);
}
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++)
{
a[i].x=r[i];
a[i].y=c[i];
if(a[i].y<a[i].x)
{
swap(a[i].x,a[i].y);
}
}
sort(a,a+n,cmp);
long long int cnt=1;
x[1]=a[0].x;
y[1]=a[0].y;
for(int i=1;i<n;i++)
{
if(a[i].x>x[cnt] && a[i].y>=y[cnt])
{
cnt++;
x[cnt]=a[i].x;
y[cnt]=a[i].y;
}
else if(a[i].x==x[cnt] && a[i].y>y[cnt])
{
x[cnt]=a[i].x;
y[cnt]=a[i].y;
}
}
n=cnt;
x[0]=0;
y[0]=0;
long long int le=0,ri=m*m,ans;
while(le<=ri)
{
long long int mid=(le+ri)/2;
int st=0,en=0;
//cout<<mid<<endl;
dp[1]=0;
t[0][0]=x[1]*x[1]-2*x[1];
t[0][1]=x[1];
t[0][2]=0;
for(int i=1;i<=n;i++)
{
while(en>=st+1 && check(st,st+1)<2*y[i])st++;
int p=t[st][2];
if(y[p-1]-x[p]+1>0 && p!=0)dp[i]=mid+dp[p]+(y[i]-x[p+1]+1)*(y[i]-x[p+1]+1)-(y[p-1]-x[p]+1)*(y[p-1]-x[p]+1);
else dp[i]=mid+dp[p]+(y[i]-x[p+1]+1)*(y[i]-x[p+1]+1);
g[i]=g[p]+1;
en++;
t[en][0]=dp[i]+x[i+1]*x[i+1]-2*x[i+1];
t[en][1]=x[i+1];
t[en][2]=i;
while(en>=st+2 && check(en,en-2)<check(en-1,en-2))en--;
//cout<<dp[i]<<" "<<g[i]<<" ";
}
//cout<<endl;
if(g[n]<=k)
{
ans=dp[n]-mid*g[n];
ri=mid-1;
}
else le=mid+1;
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In function 'bool cmp(node, node)':
aliens.cpp:13:8: warning: self-comparison always evaluates to false [-Wtautological-compare]
13 | if(a.y<a.y)return 1;
| ~~~^~~~
aliens.cpp: In function 'long long int take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:83:9: warning: 'ans' may be used uninitialized in this function [-Wmaybe-uninitialized]
83 | return ans;
| ^~~
# | 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... |