#include <bits/stdc++.h>
using namespace std;
#define int long long int
void solve() {
int k, n, extra = 0, ans = 0;
cin >> k >> n;
vector<pair<int, int>> a;
for (int i = 0; i < n; i++) {
char p, q;
int s, t;
cin >> p >> s >> q >> t;
if (p == q) {
extra += abs(s-t);
}
if (p == 'A') {
a.push_back({s, t});
} else {
a.push_back({t, s});
}
}
sort(a.begin(), a.end());
if (k == 1) {
vector<int> b;
for (int i = 0; i < n; i++) {
b.push_back(a[i].first);
b.push_back(a[i].second);
}
sort(b.begin(), b.end());
int med;
med = b[b.size()/2];
for (auto [i, j] : a) {
ans += abs(i-med);
ans += abs(j-med);
}
cout << ans+extra << endl;
} else {
cout << 0 << endl;
}
}
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
int t;
t = 1;
while(t--) {
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |