# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
951091 | 2024-03-21T06:24:28 Z | Amaarsaa | Palembang Bridges (APIO15_bridge) | C++14 | 186 ms | 16608 KB |
#include<bits/stdc++.h> using namespace std; using ll = long long ; ll Pre[100005], Suf[100005]; void DBack(multiset<ll>& A) { auto P = A.end(); P --; A.erase(P); return ; } ll Ed(multiset<ll>&A) { auto P = A.end(); P --; return *P; } bool cmp(pair < ll, ll >& A, pair < ll, ll >& B) { return A.first + A.second < B.first + B.second; } multiset < ll > deer, door; ll deer_sum =0, door_sum =0; void Insert(ll x) { if ( door.size() == deer.size()) { if (deer.empty() || *deer.begin() >= x) door.insert(x), door_sum += x; else { door_sum += *deer.begin(); deer_sum -= *deer.begin(); deer_sum += x; door.insert(*deer.begin()); deer.erase(deer.begin()); deer.insert(x); } } else { if ( Ed(door) <= x) { deer.insert(x); deer_sum += x; } else { deer_sum += Ed(door); door_sum -= Ed(door); door_sum += x; deer.insert(Ed(door)); DBack(door); door.insert(x); } } } int main() { // freopen("hayfeast.in", "r", stdin); // freopen("hayfeast.out", "w", stdout); ios::sync_with_stdio(false); cin.tie(NULL); ll t, n, m, ans, s,sum, x, y, r, p, i, j, cnt = 0; cin >> n >> m; ans = 0; sum = 0; char ch1, ch2; vector < ll > v; vector < pair < ll, ll > > q; for (i = 1; i <= m; i ++) { cin >> ch1 >> x >> ch2 >> y; if ( ch1 == ch2) { ans += abs(x - y); sum += abs(x - y); } else { v.push_back(x); v.push_back(y); q.push_back({x, y}); } } sort(v.begin(), v.end()); s = v.size(); s = (s + 1)/2 - 1; if ( n == 2) { sort(q.begin(), q.end(), cmp); for (i = 0; i < q.size(); i ++) { Insert(q[i].first); Insert(q[i].second); s = deer_sum - door_sum; Pre[i] = s; } door.clear(); deer.clear(); deer_sum = door_sum =0; ans = Pre[q.size() - 1]; for (i = q.size() - 1; i >= 0; i --) { Insert(q[i].first); Insert(q[i].second); s = deer_sum - door_sum; Suf[i] = s; if (i == 0) ans = min(ans, Suf[i]); else ans =min(ans, Suf[i] + Pre[i - 1]); } cout << ans + q.size() + sum<< endl; return 0; } for (i = 0; i < v.size(); i ++) { ans = ans + abs(v[s] - v[i]); } cout << ans + v.size()/2<< endl; }
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 | 0 ms | 360 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 380 KB | Output is correct |
7 | Correct | 1 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 | 0 ms | 344 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 1 ms | 344 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 348 KB | Output is correct |
7 | Correct | 1 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 | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 17 ms | 3800 KB | Output is correct |
13 | Correct | 33 ms | 3784 KB | Output is correct |
14 | Correct | 24 ms | 3696 KB | Output is correct |
15 | Correct | 19 ms | 2552 KB | Output is correct |
16 | Correct | 26 ms | 3804 KB | Output is correct |
17 | Correct | 23 ms | 3780 KB | Output is correct |
18 | Correct | 27 ms | 3784 KB | Output is correct |
19 | Correct | 31 ms | 3784 KB | Output is correct |
20 | Correct | 21 ms | 3780 KB | Output is correct |
21 | Correct | 29 ms | 3796 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 1 ms | 456 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 | 348 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 344 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 | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 0 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 604 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
15 | Correct | 1 ms | 604 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 | 604 KB | Output is correct |
20 | Correct | 1 ms | 604 KB | Output is correct |
21 | Correct | 1 ms | 480 KB | Output is correct |
22 | Correct | 1 ms | 616 KB | Output is correct |
23 | Correct | 1 ms | 616 KB | Output is correct |
24 | Correct | 1 ms | 616 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 360 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 344 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 | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 0 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 460 KB | Output is correct |
11 | Correct | 0 ms | 348 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 604 KB | Output is correct |
14 | Correct | 1 ms | 604 KB | Output is correct |
15 | Correct | 1 ms | 472 KB | Output is correct |
16 | Correct | 1 ms | 344 KB | Output is correct |
17 | Correct | 1 ms | 348 KB | Output is correct |
18 | Correct | 1 ms | 344 KB | Output is correct |
19 | Correct | 1 ms | 624 KB | Output is correct |
20 | Correct | 1 ms | 484 KB | Output is correct |
21 | Correct | 1 ms | 600 KB | Output is correct |
22 | Correct | 1 ms | 604 KB | Output is correct |
23 | Correct | 1 ms | 856 KB | Output is correct |
24 | Correct | 1 ms | 604 KB | Output is correct |
25 | Correct | 87 ms | 15280 KB | Output is correct |
26 | Correct | 186 ms | 15476 KB | Output is correct |
27 | Correct | 161 ms | 15944 KB | Output is correct |
28 | Correct | 163 ms | 16552 KB | Output is correct |
29 | Correct | 165 ms | 16608 KB | Output is correct |
30 | Correct | 75 ms | 8728 KB | Output is correct |
31 | Correct | 91 ms | 15824 KB | Output is correct |
32 | Correct | 100 ms | 16296 KB | Output is correct |
33 | Correct | 94 ms | 15992 KB | Output is correct |
34 | Correct | 111 ms | 16228 KB | Output is correct |
35 | Correct | 97 ms | 15800 KB | Output is correct |
36 | Correct | 116 ms | 16300 KB | Output is correct |
37 | Correct | 76 ms | 15096 KB | Output is correct |