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>
#include <bits/extc++.h>
#define int long long
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
using namespace __gnu_pbds;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int t;
signed main(){
fastio
int k, n;
cin >> k >> n;
vector<int> tmp;
int ans = 0;
vector<pair<int,int>> v;
for(int i = 0;i < n;i++){
char a,b;
int x,y;
cin >> a >> x >> b >> y;
if(a == b) ans += abs(x-y);
else{
ans++;
v.push_back({x,y});
tmp.push_back(x);
tmp.push_back(y);
}
}
if(!tmp.empty()){
sort(tmp.begin(),tmp.end());
int med = tmp[tmp.size()/2];
for(auto [x,y] : v){
ans += abs(x-med)+abs(y-med);
}
}
cout << ans << "\n";
}
# | 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... |