# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685173 | omikron123 | Palembang Bridges (APIO15_bridge) | C++14 | 1 ms | 340 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.
// https://oj.uz/problem/view/APIO15_bridge
#include <cstdio>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
// K=1,2, N=1e5
// 1. 家和办公室在同一边的是不参与计算的,和桥没有关系。
// 2. 最小值都在event点上面取得,而且是一个U型的阶梯函数,所以应该可以固定一个桥的位置,然后binary search另外一个。
// 3. 进一步可以发现K=1的时候,答案就是S[i], T[i]的median. 这已经可以得2/3的分了。
int n, K;
ll ans;
vector<pair<int,int>> x;
int main() {
scanf("%d %d", &K, &n);
for (int i = 0; i < n; i++) {
char c1[10], c2[10];
int x1, x2;
scanf("%s %d %s %d", c1, &x1, c2, &x2);
if (c1[0] == c2[0]) ans += abs(x1-x2);
else x.push_back({min(x1,x2), max(x1,x2)});
}
if (K == 1) {
// just return the median of all numbers
vector<int> X;
for (auto p: x) {
X.push_back(p.first);
X.push_back(p.second);
}
sort(X.begin(), X.end());
int m = X[X.size() / 2];
for (auto p: x) {
ans += abs(p.first-m) + abs(p.second-m);
}
} else {
}
printf("%lld", 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... |