# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
43552 | duiceman | Palembang Bridges (APIO15_bridge) | C++14 | 4 ms | 3804 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define umap unordered_map
#define pqueue priority_queue
#define mset multiset
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(),x.end()
#define long long long
#define MOD 1000000007
#define MAX (long)(1e16+5)
#define MIN (long)(-1e16-5)
#define FILEIN_ freopen("__in.txt","r",stdin)
#define FILEOUT_ freopen("__out.txt","w",stdout)
#define FILEIO_ freopen("__in.txt","r",stdin),freopen("__out.txt","w",stdout)
#define FILEIN(text) freopen(text,"r",stdin)
#define FILEOUT(text) freopen(text,"w",stdout)
#define FILEIO(text) freopen(text".in","r",stdin),freopen(text".out","w",stdout)
char c1[5],c2[5];
umap<long,long> in,out;
pair<long,long> a[100005];
main(){
long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,mid,idx,v,lst;
mset<long> pos;
//mset<long> apos;
in.reserve(200005);
out.reserve(200005);
scanf("%lld %lld",&m,&n);
if(m != 1) return 136;
for(i = 1; i <= n; i++){
scanf("%s %lld %s %lld",c1,&x,c2,&y);
x++;
y++;
if(x > y) swap(x,y);
res += abs(y-x);
if(c1[0] == c2[0]){
n--;
i--;
continue;
}
a[i] = {x,y};
res++;
}
sort(a+1,a+1+n);
l = r = 0;
y = 0;
pos.emplace(0);
auto it = pos.begin();
idx = v = 0;
for(i = 1; i <= n; i++){
x = a[i].x;
y = a[i].y;
in[x]++;
out[y]++;
pos.emplace(x);
pos.emplace(y);
if(x > v){
r++;
res += (x-v)*2;
}
else if(y <= v){
// printf(">>>>>> %d %d\n",y,v);
l++;
res += (v-y)*2;
}
if(x <= v){
idx++;
}
// apos.emplace(x);
// apos.emplace(y);
mid = (pos.size()-1)/2+1;
// printf("> %d %d\n",x,y);
while(idx < mid){
// printf("en = %d\n",v);
while(*it != v) it++;
idx++;
// printf("bef %d\n",*it);
it++;
// printf("now %d\n",*it);
lst = v;
v = *it;
if(v == lst) continue;
res -= (v-lst)*r*2;
res += (v-lst)*l*2;
r -= in[v];
l += out[v];
// printf(">>>>>> %d = %d\n",v,out[v]);
// printf("%d : %d (%d %d)\n",v,res,l,r);
}
}
printf("%lld\n",res);
return 0;
}
컴파일 시 표준 에러 (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... |