# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
764203 | 2023-06-23T08:33:42 Z | qwerasdfzxcl | Palembang Bridges (APIO15_bridge) | C++17 | 52 ms | 4240 KB |
#include <bits/stdc++.h> using namespace std; #define MAXN 100005 #define pb push_back #define sz(v) ((int)(v).size()) #define all(v) (v).begin(), (v).end() typedef long long lld; int K, N, M; lld D[MAXN], E[MAXN]; struct Z{ int a, b; } A[MAXN]; void proc(lld V[]) { if (!N) return; lld val = abs(A[1].a - A[1].b); priority_queue <int> p, q; int mid = A[1].a; if (A[1].b < mid) p.push(A[1].b); else q.push(-A[1].b); V[1] = val; for (int i=2;i<=N;i++){ val += abs(mid - A[i].a) + abs(mid - A[i].b); if (A[i].a < mid) p.push(A[i].a); else q.push(-A[i].a); if (A[i].b < mid) p.push(A[i].b); else q.push(-A[i].b); while (sz(p) < sz(q)){ int nxt = -q.top(); q.pop(); p.push(mid); val += (lld)(nxt - mid) * sz(p) - (lld)(nxt - mid) * (sz(q) + 1); mid = nxt; } while (sz(p) > sz(q)+1){ int nxt = p.top(); p.pop(); q.push(-mid); val += (lld)(mid - nxt) * sz(q) - (lld)(mid - nxt) * (sz(p) + 1); mid = nxt; } V[i] = val; } } int main() { scanf("%d%d", &K, &M); vector <int> arr; lld def = 0; while (M--){ char p, q; int a, b; scanf(" %c%d %c%d", &p, &a, &q, &b); if (p == q){ def += abs(a-b); continue; } A[++N] = {a, b}; } sort(A+1, A+N+1, [](const Z &a, const Z &b){ return a.a+a.b < b.a+b.b; }); proc(D); if (K == 1){ printf("%lld\n", D[N] + def + N); return 0; } reverse(A+1, A+N+1); proc(E); lld ans = 1e18; for (int i=0;i<=N;i++) ans = min(ans, def + D[i] + E[N-i] + N); printf("%lld\n", ans); }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 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 | 340 KB | Output is correct |
6 | Correct | 1 ms | 212 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 | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 1 ms | 340 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 | 340 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 | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 23 ms | 2880 KB | Output is correct |
13 | Correct | 39 ms | 2760 KB | Output is correct |
14 | Correct | 30 ms | 2524 KB | Output is correct |
15 | Correct | 22 ms | 1816 KB | Output is correct |
16 | Correct | 23 ms | 2748 KB | Output is correct |
17 | Correct | 33 ms | 2784 KB | Output is correct |
18 | Correct | 23 ms | 2872 KB | Output is correct |
19 | Correct | 37 ms | 2804 KB | Output is correct |
20 | Correct | 28 ms | 2760 KB | Output is correct |
21 | Correct | 38 ms | 2856 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 212 KB | Output is correct |
11 | Correct | 1 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
11 | Correct | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 212 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 | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 352 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 0 ms | 212 KB | Output is correct |
3 | Correct | 0 ms | 212 KB | Output is correct |
4 | Correct | 0 ms | 212 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 212 KB | Output is correct |
7 | Correct | 0 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 | 0 ms | 212 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 340 KB | Output is correct |
14 | Correct | 1 ms | 340 KB | Output is correct |
15 | Correct | 1 ms | 340 KB | Output is correct |
16 | Correct | 0 ms | 212 KB | Output is correct |
17 | Correct | 0 ms | 340 KB | Output is correct |
18 | Correct | 0 ms | 212 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 | 340 KB | Output is correct |
22 | Correct | 1 ms | 340 KB | Output is correct |
23 | Correct | 1 ms | 340 KB | Output is correct |
24 | Correct | 1 ms | 340 KB | Output is correct |
25 | Correct | 26 ms | 3904 KB | Output is correct |
26 | Correct | 36 ms | 3896 KB | Output is correct |
27 | Correct | 48 ms | 3832 KB | Output is correct |
28 | Correct | 49 ms | 3884 KB | Output is correct |
29 | Correct | 49 ms | 3896 KB | Output is correct |
30 | Correct | 25 ms | 2236 KB | Output is correct |
31 | Correct | 24 ms | 3880 KB | Output is correct |
32 | Correct | 41 ms | 3856 KB | Output is correct |
33 | Correct | 26 ms | 3844 KB | Output is correct |
34 | Correct | 47 ms | 3864 KB | Output is correct |
35 | Correct | 34 ms | 4240 KB | Output is correct |
36 | Correct | 52 ms | 3800 KB | Output is correct |
37 | Correct | 29 ms | 3780 KB | Output is correct |