# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
997355 | doducanh | Palembang Bridges (APIO15_bridge) | C++14 | 4 ms | 480 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;
main()
{
cin>>k>>n;
vector<ii>v;
set<int>s;
int 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');
s.insert(a[i].yo);
s.insert(a[i].yt);
if(xo==xt){
delt+=abs(a[i].yt-a[i].yo);
}
else v.push_back({a[i].yo,a[i].yt});
}
long long ans=1e18+7;
for(int to:s){
long long s=0;
for(auto [x,y]:v){
s=s+((long long)(abs(x-to)+abs(y-to))+1);
}
ans=min(ans,s);
}
cout<<ans+delt;
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... |