# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
43460 | duiceman | Palembang Bridges (APIO15_bridge) | C++14 | 4 ms | 3656 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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<int,int> a[100005];
main(){
long t,i,j,k,n,m,x,y,res=0,l=0,r=0,mn=MAX,rr,mx=0;
set<long> pos,rpos;
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 += y-x;
if(c1[0] == c2[0]){
n--;
i--;
continue;
}
a[i] = {x,y};
res++;
in[x]++;
out[y]++;
pos.emplace(x);
pos.emplace(y);
mx = max(mx,y);
}
for(x = 1; x <= mx; x++){
rr = res;
for(i = 1; i <= n; i++){
if(x >= a[i].x && x <= a[i].y) continue;
rr += min(abs(a[i].x-x),abs(a[i].y-x))*2;
}
if(rr < mn){
rpos.clear();
rpos.emplace(x);
mn = rr;
}
else if(rr == mn){
rpos.emplace(x);
mn = rr;
}
// printf("%d -> %d\n",x,rr);
}
bool ok = false;
for(long x : rpos){
if(pos.find(x) != pos.end() || in[x] || out[x]){
ok = true;
break;
}
}
if(!ok){
return 136;
}
/*l = r = 0;
for(long x : pos){
res += x*2*in[x];
r += in[x];
}
y = 0;
for(long x : pos){
res -= (x-y)*r*2;
res += (x-y)*l*2;
r -= in[x];
l += out[x];
mn = min(mn,res);
y = x;
}*/
printf("%lld\n",mn);
return 0;
}
Compilation message (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... |