이 제출은 이전 버전의 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, k; };
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;
pll 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, S[pos].k};
}
void init()
{
S.clear();
pos=0;
}
} cht;
int N, M, K;
Point B[MAXN+10], A[MAXN+10];
pll dp[MAXN+10];
ll solve(ll lambda)
{
int i, j;
cht.init();
for(i=1; i<=N; i++)
{
dp[i]={2*(A[i].y-A[1].x+1)*(A[i].y-A[1].x+1)+lambda, 1};
if(i!=1)
{
pll val=cht.query(A[i].y);
dp[i]=min(dp[i], {val.first+2*A[i].y*A[i].y+lambda, val.second+1});
}
cht.update({-2*2*(A[i+1].x-1), 2*(A[i+1].x-1)*(A[i+1].x-1)-2*max(0ll, A[i].y-A[i+1].x+1)*max(0ll, A[i].y-A[i+1].x+1)+dp[i].first, dp[i].second});
}
return dp[N].second;
}
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);
ll lo=-1, hi=1e15;
while(lo+1<hi)
{
ll mid=lo+hi>>1;
if(solve(mid*2+1)>K) lo=mid;
else hi=mid;
}
solve(hi*2);
ll ans=dp[N].first/2-K*hi;
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
aliens.cpp: In member function 'pll CHT::query(ll)':
aliens.cpp:28:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(S.size()<=pos) pos=S.size()-1;
~~~~~~~~^~~~~
aliens.cpp:29: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 solve(ll)':
aliens.cpp:46:12: warning: unused variable 'j' [-Wunused-variable]
int i, j;
^
aliens.cpp: In function 'll take_photos(int, int, int, std::vector<int>, std::vector<int>)':
aliens.cpp:82:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
ll mid=lo+hi>>1;
~~^~~
aliens.cpp:63:12: warning: unused variable 'j' [-Wunused-variable]
int i, j, k;
^
aliens.cpp:63: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... |