# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110946 | PeppaPig | Palembang Bridges (APIO15_bridge) | C++14 | 4 ms | 384 KiB |
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>
#define long long long
#define pii pair<int, int>
#define x first
#define y second
using namespace std;
const int N = 1e5+5;
int k, n;
long ans;
vector<pii> v;
int main() {
scanf("%d %d", &k, &n);
for(int i = 1; i <= n; i++) {
char a, c; int b, d;
scanf(" %c %d %c %d", &a, &b, &c, &d);
if(b > d) swap(b, d);
if(a == c) ans += d - b;
else v.emplace_back(b, d);
}
n = v.size(), ans += n;
if(!v.empty()) {
sort(v.begin(), v.end(), [&](const pii &a, const pii &b) {
return a.x + a.y < b.x + b.y;
});
if(k == 1) {
int bridge = (v[(n - 1) / 2].x + v[(n - 1) / 2].y) / 2;
for(int i = 0; i < n; i++) {
ans += abs(bridge - v[i].x);
ans += abs(bridge - v[i].y);
}
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | 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... |