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 int int64_t
#define pii array<int,2>
signed main() {
int k, n;cin>>k>>n;
vector<pii> dif;
int dis = 0;
for (int i=0;i<n;i++) {
char c1,c2;
int p1,p2;
cin>>c1>>p1>>c2>>p2;
if (c1 == c2) {
dis += abs(p1-p2);
}
else {
dif.push_back({p1,p2});
}
}
if (k == 1) {
if (dif.size() == 0) {
cout<<dis<<"\n";
return 0;
}
vector<int> al;
for (auto x:dif) {
al.push_back(x[0]);
al.push_back(x[1]);
}
sort(al.begin(),al.end());
int med = al[al.size() / 2];
for (int x:al) {
dis += abs(x - med);
}
dis += dif.size();
cout<<dis<<"\n";
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... |