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;
using ll = long long;
using pii = pair<int, int>;
#define F first
#define S second
using pip = pair<int, pii>; // (s+t)/2, s, t
constexpr int sc = 4;
constexpr int maxx = 2e9 + 18;
constexpr int maxn = 1e5 + 18;
int cost;
int n, k;
vector<int> endpts;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> k >> n;
for (int i = 0; i < n; i++) {
char s1, t1;
int s, t;
cin >> s1 >> s >> t1 >> t;
if (s1 == t1) {
cost += sc * abs(t - s);
// cout << '+' << sc * abs(t - s) << '\n';
} else {
endpts.push_back(sc * s);
endpts.push_back(sc * t);
}
}
sort(endpts.begin(), endpts.end());
if (k == 1) {
int eps = endpts.size() / 2;
if (eps != 0) {
int bloc = (endpts[eps] + endpts[eps - 1]) / 2;
for (int x : endpts) {
cost += abs(bloc - x);
// cout << '+' << abs(bloc - x) << '\n';
}
cost += (eps * sc);
// cout << '+' << eps * sc << '\n';
}
cout << cost / sc << '\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... |