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;
main()
{
cin>>k>>n;
vector<ii>v;
vector<int>tmp;
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});
}
}
long long ans=LLONG_MAX;
sort(tmp.begin(),tmp.end());
int to=tmp[tmp.size()/2];
long long s=0ll;
for(auto [x,y]:v){
s=s+((abs(x-to)+abs(y-to))+1);
}
ans=min(ans,s);
// if(tmp.size()/2-1>=0){
// to=tmp[tmp.size()/2-1];
// s=0ll;
// for(auto [x,y]:v)
// {
// s=s+((abs(x-to)+abs(y-to))+1);
// }
// ans=min(ans,s);
// }
// if(tmp.size()/2+1<tmp.size()){
// to=tmp[tmp.size()/2+1];
// s=0ll;
// for(auto [x,y]:v)
// {
// s=s+((abs(x-to)+abs(y-to))+1);
// }
// ans=min(ans,s);
// }
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)
bridge.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | main()
| ^~~~
bridge.cpp: In function 'int main()':
bridge.cpp:36:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
36 | for(auto [x,y]:v){
| ^
# | 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... |