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 sameside = 0, k, n, m = 0, ans = 0; cin >> k >> n;
vector<int> v(2 * n + 5);
for (int i = 1; i <= n; i++) {
char p, q; int s, t; cin >> p >> s >> q >> t;
if (p == q) sameside += abs(s - t);
else {
m++; v[m] = s;
m++; v[m] = t;
}
}
if (k == 1) {
sort(v.begin() + 1, v.begin() + m + 1);
int bridge = v[(m + 1) / 2];
for (int i = 1; i <= m; i += 2) {
ans += abs(bridge - v[i]) + abs(bridge - v[i + 1]) + 1;
}
cout << ans + sameside << "\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... |