이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "squad.h"
#include <bits/stdc++.h>
using namespace std;
struct Point{
long long x, y;
int ind;
bool operator <(const Point A) const{
if(x==A.x) return y<A.y;
return x<A.x;
}
};
vector<Point> pa, pb;
int n;
bool chk(Point a, Point b, Point c){
return (a.y-b.y)*(c.x-b.x) >= (b.y-c.y)* (b.x-a.x);
}
vector<Point> f(vector<Point> in){
vector<Point> ret;
for(auto i:in){
while(!ret.empty()&&ret[ret.size()-1].y<=i.y) ret.pop_back();
while(ret.size()>1&&chk(ret[ret.size()-2],ret[ret.size()-1],i)) ret.pop_back();
ret.push_back(i);
}
return ret;
}
void Init(std::vector<int> A, std::vector<int> D, std::vector<int> P){
n = A.size();
for(int i=0;i<n;i++){
pa.push_back({A[i],P[i],i});
pb.push_back({D[i],P[i],i});
}
sort(pa.begin(), pa.end());
sort(pb.begin(), pb.end());
pa = f(pa);
pb = f(pb);
/*
cout<<"pa --------------\n";
for(auto i:pa){
cout<<i.x<<" "<<i.y<<" "<<i.ind<<"\n";
}
cout<<"pb --------------\n";
for(auto i:pb){
cout<<i.x<<" "<<i.y<<" "<<i.ind<<"\n";
}
cout<<"end of debug-----\n";
*/
}
long long BestSquad(int X, int Y){
int l=0,r=pa.size()-2,inda=0,indb=0;
while(l<r){
int mid = (l+r)/2;
if((pa[mid].y-pa[mid+1].y)*Y<(pa[mid+1].x-pa[mid].x)*X)
{
inda=max(inda,mid+1);
l=mid+1;
}
else r=mid-1;
}
l=0;r=pb.size()-2;
while(l<r){
int mid = (l+r)/2;
if((pb[mid].y-pb[mid+1].y)*Y<(pb[mid+1].x-pb[mid].x)*X)
{
indb=max(indb,mid+1);
l=mid+1;
}
else r=mid-1;
}
//cout<<"inda : "<<inda<<" indb : "<<indb<<endl;
long long ret=0;
for(int i=-3;i<=3;i++){
for(int j=-3;j<=3;j++){
int aa=inda+i, bb=indb+j;
if(0<=aa&&aa<pa.size()&&0<=bb&&bb<pb.size()&&pa[aa].ind!=pb[bb].ind){
long long t = (pa[aa].x+pb[bb].x)*X+(pa[aa].y+pb[bb].y)*Y;
//cout<<"check "<<aa<<" "<<bb<<" "<<t<<"\n";
if(ret<t) ret=t;
}
}
}
return ret;
}
컴파일 시 표준 에러 (stderr) 메시지
squad.cpp: In function 'long long int BestSquad(int, int)':
squad.cpp:78:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(0<=aa&&aa<pa.size()&&0<=bb&&bb<pb.size()&&pa[aa].ind!=pb[bb].ind){
~~^~~~~~~~~~
squad.cpp:78:37: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if(0<=aa&&aa<pa.size()&&0<=bb&&bb<pb.size()&&pa[aa].ind!=pb[bb].ind){
~~^~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |