# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
612458 | 2022-07-29T15:28:31 Z | DeMen100ns | Palembang Bridges (APIO15_bridge) | C++17 | 94 ms | 5476 KB |
#include <bits/stdc++.h> using namespace std; using ll=long long; using PQ=priority_queue<int>; struct pii { int l, r; bool operator<(pii b) const { return l+r<b.l+b.r; } }; int main() { int K, N, M=0; scanf("%d%d", &K, &N); pii A[N]; ll B[N], s=0, w=0; for(int i=0; i<N; i++) { char a, b; int l, r; scanf(" %c%d %c%d", &a, &l, &b, &r); if(l>r) swap(l, r); if(a!=b) A[M++]={l, r}; else s+=r-l; } s+=N=M; sort(A, A+N); PQ L, R; auto add=[&](pii v) { L.push(v.l), R.push(-v.r); w+=v.r-v.l; if(L.top()>-R.top()) { int l=L.top(), r=-R.top(); L.pop(), R.pop(); L.push(r), R.push(-l); w+=(l-r)*2; } return w; }; for(int i=0; i<N; i++) B[i]=add(A[i]); w=0; PQ().swap(L); PQ().swap(R); ll t=N ? B[N-1] : 0; if(N && K==2) for(int i=N; --i;) t=min(t, add(A[i])+B[i-1]); printf("%lld\n", s+t); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 312 KB | Output is correct |
5 | Correct | 1 ms | 308 KB | Output is correct |
6 | Correct | 1 ms | 316 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 300 KB | Output is correct |
4 | Correct | 1 ms | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 KB | Output is correct |
6 | Correct | 1 ms | 308 KB | Output is correct |
7 | Correct | 1 ms | 340 KB | Output is correct |
8 | Correct | 1 ms | 340 KB | Output is correct |
9 | Correct | 1 ms | 340 KB | Output is correct |
10 | Correct | 1 ms | 316 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
12 | Correct | 32 ms | 3596 KB | Output is correct |
13 | Correct | 57 ms | 5160 KB | Output is correct |
14 | Correct | 47 ms | 3880 KB | Output is correct |
15 | Correct | 34 ms | 3220 KB | Output is correct |
16 | Correct | 34 ms | 4508 KB | Output is correct |
17 | Correct | 53 ms | 5148 KB | Output is correct |
18 | Correct | 37 ms | 4760 KB | Output is correct |
19 | Correct | 63 ms | 5160 KB | Output is correct |
20 | Correct | 45 ms | 4640 KB | Output is correct |
21 | Correct | 56 ms | 4896 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 1 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 288 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 1 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 300 KB | Output is correct |
12 | Correct | 1 ms | 300 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 212 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 340 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 308 KB | Output is correct |
23 | Correct | 1 ms | 312 KB | Output is correct |
24 | Correct | 2 ms | 340 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 300 KB | Output is correct |
3 | Correct | 1 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 300 KB | Output is correct |
5 | Correct | 0 ms | 300 KB | Output is correct |
6 | Correct | 1 ms | 212 KB | Output is correct |
7 | Correct | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 0 ms | 212 KB | Output is correct |
10 | Correct | 1 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 1 ms | 296 KB | Output is correct |
13 | Correct | 1 ms | 212 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 1 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 300 KB | Output is correct |
18 | Correct | 1 ms | 300 KB | Output is correct |
19 | Correct | 1 ms | 340 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 332 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 312 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 38 ms | 3860 KB | Output is correct |
26 | Correct | 57 ms | 3992 KB | Output is correct |
27 | Correct | 75 ms | 4836 KB | Output is correct |
28 | Correct | 79 ms | 5452 KB | Output is correct |
29 | Correct | 71 ms | 5392 KB | Output is correct |
30 | Correct | 41 ms | 3048 KB | Output is correct |
31 | Correct | 36 ms | 4740 KB | Output is correct |
32 | Correct | 89 ms | 5476 KB | Output is correct |
33 | Correct | 43 ms | 4996 KB | Output is correct |
34 | Correct | 94 ms | 5376 KB | Output is correct |
35 | Correct | 58 ms | 4912 KB | Output is correct |
36 | Correct | 84 ms | 5124 KB | Output is correct |
37 | Correct | 35 ms | 3888 KB | Output is correct |