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 futaba ios_base::sync_with_stdio(false); cin.tie(NULL);
#define rio return 0;
#define ll long long
#define fi first
#define se second
// Fun things are fun. //
int main() {
/* freopen(".txt", "r", stdin);
freopen(".txt", "w", stdout); */
futaba
ll k, n;
cin >> k >> n;
ll ans = 0;
if(k == 1) {
vector<ll> v;
vector<pair<ll, ll>> v2;
while(n--) {
char p, q;
ll s, t;
cin >> p >> s >> q >> t;
if(p == q) ans += abs(s - t);
else {
v.push_back(abs(s - t) + 1);
v2.push_back({s, t});
}
}
sort(v.begin(), v.end());
ll x = v[(int)v.size() / 2];
for(auto i : v2) ans += (abs(i.fi - x) + abs(i.se - x)) + 1;
cout << ans << '\n';
}
rio
}
| # | 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... |