# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
110935 | PeppaPig | Palembang Bridges (APIO15_bridge) | C++14 | 3 ms | 512 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();
sort(v.begin(), v.end(), [&](const pii &a, const pii &b) {
return a.x + a.y < b.x + b.y;
});
if(k == 1) {
pii pos = v[(n - 1) / 2];
int bridge = (pos.x + pos.y) / 2;
for(int i = 0; i < n; i++) {
++ans;
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... |