# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
942982 | 2024-03-11T07:31:41 Z | oblantis | Palembang Bridges (APIO15_bridge) | C++17 | 206 ms | 14460 KB |
#include <bits/stdc++.h> using namespace std; #define mp make_pair typedef pair<int, int> pii; vector<int> points; long long easy; long long ans; long long lt[110000]; long long rt[110000]; int n, k; vector< pii > bridge; bool compara(pii a, pii b) { return a.first + a.second < b.first + b.second; } template<class T> void calc(T it, T ed, long long *arr) { multiset<int> sm; multiset<int> bg; long long ssm = 0; long long sbg = 0; int c = 0; arr[c++] = 0; while (it != ed) { sm.insert(it->first); ssm += it->first; bg.insert(it->second); sbg += it->second; while (*sm.rbegin() > *bg.begin()) { sbg += *sm.rbegin() - *bg.begin(); ssm += *bg.begin() - *sm.rbegin(); bg.insert(*sm.rbegin()); sm.insert(*bg.begin()); bg.erase(bg.begin()); sm.erase(--sm.end()); } arr[c++] = sbg - ssm; it++; } } int main() { scanf("%d %d", &k, &n); for (int i = 0; i < n; i++) { char t1, t2; int x, y; scanf(" %c %d %c %d", &t1, &x, &t2, &y); if (t1 == t2) easy += abs(y-x); else bridge.push_back(mp(x, y)); } sort(bridge.begin(), bridge.end(), compara); calc(bridge.begin(), bridge.end(), lt); // prefixes calc(bridge.rbegin(), bridge.rend(), rt); // suffixes n = bridge.size(); if (k == 1) { ans = rt[n]; } else { ans = 1000000000000000000LL; for (int in_lt = 0; in_lt <= n; in_lt++) { ans = min(ans, lt[in_lt] + rt[n - in_lt]); } } printf("%lld\n", easy + ans + n); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 476 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 2 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 456 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 2 ms | 344 KB | Output is correct |
5 | Correct | 2 ms | 344 KB | Output is correct |
6 | Correct | 1 ms | 344 KB | Output is correct |
7 | Correct | 2 ms | 344 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 456 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 106 ms | 12844 KB | Output is correct |
13 | Correct | 206 ms | 14280 KB | Output is correct |
14 | Correct | 152 ms | 12044 KB | Output is correct |
15 | Correct | 89 ms | 8652 KB | Output is correct |
16 | Correct | 90 ms | 13760 KB | Output is correct |
17 | Correct | 122 ms | 14272 KB | Output is correct |
18 | Correct | 85 ms | 13932 KB | Output is correct |
19 | Correct | 123 ms | 14460 KB | Output is correct |
20 | Correct | 109 ms | 13804 KB | Output is correct |
21 | Correct | 126 ms | 14024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 344 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 604 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 344 KB | Output is correct |
8 | Correct | 1 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 344 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 348 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 348 KB | Output is correct |
22 | Correct | 1 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 2 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 344 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 344 KB | Output is correct |
14 | Correct | 1 ms | 348 KB | Output is correct |
15 | Correct | 1 ms | 348 KB | Output is correct |
16 | Correct | 1 ms | 348 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 348 KB | Output is correct |
19 | Correct | 1 ms | 452 KB | Output is correct |
20 | Correct | 1 ms | 348 KB | Output is correct |
21 | Correct | 1 ms | 344 KB | Output is correct |
22 | Correct | 2 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 348 KB | Output is correct |
24 | Correct | 1 ms | 348 KB | Output is correct |
25 | Correct | 98 ms | 12896 KB | Output is correct |
26 | Correct | 144 ms | 12996 KB | Output is correct |
27 | Correct | 170 ms | 13764 KB | Output is correct |
28 | Correct | 176 ms | 14280 KB | Output is correct |
29 | Correct | 169 ms | 14448 KB | Output is correct |
30 | Correct | 77 ms | 7368 KB | Output is correct |
31 | Correct | 91 ms | 13588 KB | Output is correct |
32 | Correct | 117 ms | 14004 KB | Output is correct |
33 | Correct | 84 ms | 13740 KB | Output is correct |
34 | Correct | 123 ms | 13764 KB | Output is correct |
35 | Correct | 121 ms | 13568 KB | Output is correct |
36 | Correct | 120 ms | 13912 KB | Output is correct |
37 | Correct | 84 ms | 12744 KB | Output is correct |