이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "aliens.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
struct Point
{
ll y, x;
};
struct CHT
{
struct Line { ll a, b; };
double cross(const Line &p, const Line &q) { return (double)(q.b-p.b)/(p.a-q.a); }
vector<Line> S;
void update(Line p)
{
while(S.size()>1 && cross(S[S.size()-1], p)<=cross(S[S.size()-1], S[S.size()-2])) S.pop_back();
S.push_back(p);
}
int pos=0;
ll query(ll x)
{
if(S.size()<=pos) pos=S.size()-1;
else while(pos+1<S.size() && cross(S[pos], S[pos+1])<=x) pos++;
return S[pos].a*x+S[pos].b;
}
void init()
{
S.clear();
pos=0;
}
} cht;
int N, M, K;
Point B[MAXN+10], A[MAXN+10];
ll dp[3][MAXN+10];
ll take_photos(int _N, int _M, int _K, vector<int> R, vector<int> C)
{
int i, j, k;
N=_N; M=_M; K=_K;
for(i=1; i<=N; i++) B[i]={min(R[i-1], C[i-1]), max(R[i-1], C[i-1])};
sort(B+1, B+N+1, [&](const Point &p, const Point &q)
{
if(p.y==q.y) return p.x>q.x;
return p.y<q.y;
});
int cnt=1;
ll val=-1;
for(i=1; i<=N; i++) if(val<B[i].x) A[cnt++]=B[i], val=B[i].x;
N=cnt-1;
for(i=1; i<=N; i++) if(A[i].x>A[i].y) swap(A[i].x, A[i].y);
for(i=1; i<=N; i++) dp[1][i]=(A[i].y-A[1].x+1)*(A[i].y-A[1].x+1);
/*
for(i=2; i<=K; i++)
{
for(j=1; j<=N; j++)
{
dp[i][j]=(A[j].y-A[1].x+1)*(A[j].y-A[1].x+1);
for(k=2; k<=j; k++) dp[i][j]=min(dp[i][j], dp[i-1][k-1]+(A[j].y-A[k].x+1)*(A[j].y-A[k].x+1)-max(0ll, A[k-1].y-A[k].x+1)*max(0ll, A[k-1].y-A[k].x+1));
}
}
*/
for(i=2; i<=K; i++)
{
cht.init();
dp[i&1][1]=(A[1].y-A[1].x+1)*(A[1].y-A[1].x+1);
for(j=2; j<=N; j++)
{
cht.update({-2*A[j].x, dp[i-1&1][j-1]+(A[j].x-1)*(A[j].x-1)-max(0ll, A[j-1].y-A[j].x+1)*max(0ll, A[j-1].y-A[j].x+1)});
dp[i&1][j]=min((A[j].y-A[1].x+1)*(A[j].y-A[1].x+1), cht.query(A[j].y)+A[j].y*A[j].y+2*A[j].y);
}
}
//for(i=1; i<=K; i++) { for(j=1; j<=N; j++) printf("%lld ", dp[i][j]); printf("\n"); }
return dp[K&1][N];
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In member function 'll CHT::query(ll)':
aliens.cpp:31:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(S.size()<=pos) pos=S.size()-1;
~~~~~~~~^~~~~
aliens.cpp:32:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
else while(pos+1<S.size() && cross(S[pos], S[pos+1])<=x) pos++;
~~~~~^~~~~~~~~
aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:84:40: warning: suggest parentheses around '-' in operand of '&' [-Wparentheses]
cht.update({-2*A[j].x, dp[i-1&1][j-1]+(A[j].x-1)*(A[j].x-1)-max(0ll, A[j-1].y-A[j].x+1)*max(0ll, A[j-1].y-A[j].x+1)});
~^~
aliens.cpp:49:15: warning: unused variable 'k' [-Wunused-variable]
int i, j, k;
^
# | 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... |