# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
685175 | 2023-01-23T16:23:16 Z | omikron123 | Palembang Bridges (APIO15_bridge) | C++14 | 1 ms | 340 KB |
// 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) + 1; } } else { } printf("%lld", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 340 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 1 ms | 340 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Incorrect | 0 ms | 212 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |