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;
int n,k;
long long ans=0;
int main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>k>>n;
vector<pair<int,int>>vec;
vector<int>pos;
for(int i=1;i<=n;i++)
{
char a,b;int x,y;
cin>>a>>x>>b>>y;
if(a==b)ans+=abs(x-y);
else {vec.push_back({x,y});pos.push_back(x);pos.push_back(y);}
}
ans+=vec.size();
sort(pos.begin(),pos.end());
int vv=pos.size();
int vvv=pos[vv/2];
for(auto v:vec)ans+=abs(v.first-vvv)+abs(v.second-vvv);
cout<<ans;
return 0;;
}
# | 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... |