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 long long
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int k, n;
cin >> k >> n;
vector<pair<pair<char, int>, pair<char, int>>> a(n);
vector<int> pos;
for (int i = 0; i < n; i++) {
cin >> a[i].first.first >> a[i].first.second;
cin >> a[i].second.first >> a[i].second.second;
if (a[i].first.first != a[i].second.first) {
pos.push_back(a[i].first.second);
pos.push_back(a[i].second.second);
}
}
sort(pos.begin(), pos.end());
int median = pos[(int)pos.size() / 2];
int ans = 0;
for (int i = 0; i < n; i++) {
if (a[i].first.first != a[i].second.first) {
ans += abs(median - a[i].first.second);
ans += abs(median - a[i].second.second);
ans += 1;
} else {
ans += abs(a[i].first.second - a[i].second.second);
}
}
cout << ans;
}
/*
1 5
B 0 A 4
B 1 B 3
A 5 B 7
B 2 A 6
B 1 A 7
*/
# | 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... |