# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
997380 | doducanh | Palembang Bridges (APIO15_bridge) | C++14 | 184 ms | 6040 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 ii pair<int,int>
const int maxn=1e5+7;
struct nguoi
{
int xo,yo,xt,yt;
};
nguoi a[maxn];
int k,n;
vector<ii>v;
vector<int>tmp;
long long f(int t)
{
long long sum=0;
for(auto [x,y]:v){
sum+=(abs(x-t)+abs(y-t)+1);
}
return sum;
}
main()
{
cin>>k>>n;
long long delt=0;
for(int i=1;i<=n;i++){
char xo,xt;
cin>>xo>>a[i].yo>>xt>>a[i].yt;
a[i].xo=(xo=='B');
a[i].xt=(xt=='B');
if(xo==xt){
delt+=abs(a[i].yt-a[i].yo);
}
else{
tmp.push_back(a[i].yo);
tmp.push_back(a[i].yt);
v.push_back({a[i].yo,a[i].yt});
}
}
int l=0,r=1e9+7;
while(r-l>1000){
int m1=l+(r-l)/3;
int m2=r-(r-l)/3;
if(f(m1)<f(m2)){
r=m2;
}
else l=m1;
}
// for(auto [x,y]:v){
// cout<<x<<" "<<y<<"\n";
// }
long long ans=LLONG_MAX;
for(auto i=l;i<=r;i++){
ans=min(ans,f(i));
// if(f(i)==18)cout<<i;
// cout<<f(i)<<"\n";
}
cout<<ans+delt;
return 0;
}
/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
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... |