# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
17412 | comet | Palembang Bridges (APIO15_bridge) | C++98 | 0 ms | 4304 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cstdio>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define pb push_back
struct pt{
ll x,y;
bool operator<(const pt& r)const{
return x+y<r.x+r.y;
}
};
int K,N,sz;
ll base,ans,sum;
ll L[100010],R[100010];
pt a[100010];
priority_queue<ll> lo;
priority_queue<ll,vector<ll>,greater<ll> > hi;
void push(int x){
if(!hi.empty()&&x>=hi.top())hi.push(x);
else lo.push(x);
ll t;
while(hi.size()+1<lo.size()){
t=lo.top();lo.pop();
hi.push(t);
}
while(hi.size()>lo.size()+1){
t=hi.top();hi.pop();
lo.push(t);
}
}
void f(ll s[]){
vector<int> ret;
for(int i=0;i<sz;i++){
ret.pb(a[i].x);
ret.pb(a[i].y);
sort(ret.begin(),ret.end());
int mid=(ret[ret.size()/2]);
for(int j=0;j<=i;j++){
s[i]+=abs(a[j].x-mid);
s[i]+=abs(a[j].y-mid);
}
}
}
int main(){
//freopen("bridge.in","r",stdin);
scanf("%d%d ",&K,&N);
char tx,ty;
ll x,y;
for(int i=0;i<N;i++){
scanf("%c %lld %c %lld ",&tx,&x,&ty,&y);
if(tx==ty){
base+=y-x-1;
}else{
a[sz++]=pt{x,y};
}
}
base+=N;
sort(a,a+sz);
f(L);
if(K==1){
printf("%lld",L[sz-1]+base);
return 0;
}
reverse(a,a+sz);
f(R);
ans=-1e18;
for(int i=0;i<sz;i++){
ans=max(ans,L[i]+R[sz-1-i]);
}
printf("%lld",ans+base);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |