# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
338543 | 2020-12-23T10:55:24 Z | shahriarkhan | Palembang Bridges (APIO15_bridge) | C++14 | 106 ms | 5728 KB |
#include <bits/stdc++.h> using namespace std ; bool cmp(pair<int,int> a , pair<int,int> b) { return a.first + a.second < b.first + b.second ; } priority_queue<int> l ; priority_queue<int , vector<int> , greater<int> > r ; long long lsum , rsum ; void append(int x) { int median = (l.size() ? l.top() : 1000000001) ; if(x <= median) { l.push(x) ; lsum += x ; } else { r.push(x) ; rsum += x ; } if(r.size() + 1 < l.size()) { int next = l.top() ; l.pop() ; r.push(next) ; lsum -= next ; rsum += next ; } else if(l.size() < r.size()) { int next = r.top() ; r.pop() ; l.push(next) ; rsum -= next ; lsum += next ; } } long long pref[100001] ; int main() { int k , n ; scanf("%d%d",&k,&n) ; long long same_side = 0 ; vector<pair<int,int> > v = {{0,0}} ; for(int i = 0 ; i < n ; ++i) { char a , b ; int x , y ; scanf(" %c%d %c%d",&a,&x,&b,&y) ; if(a==b) same_side += abs(x-y) ; else v.push_back({x,y}) ; } sort(v.begin(),v.end(),cmp) ; n = v.size() - 1 ; same_side += n ; lsum = rsum = 0 ; for(int i = 1 ; i <= n ; ++i) { append(v[i].first) ; append(v[i].second) ; pref[i] = rsum - lsum ; } long long ans = pref[n] ; if(k==2) { while(!l.empty()) l.pop() ; while(!r.empty()) r.pop() ; lsum = rsum = 0 ; for(int i = n ; i >= 1 ; --i) { append(v[i].first) ; append(v[i].second) ; ans = min(ans , rsum - lsum + pref[i-1]) ; } } printf("%lld\n",same_side + ans) ; return 0 ; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 2 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 2 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 41 ms | 3936 KB | Output is correct |
13 | Correct | 65 ms | 5600 KB | Output is correct |
14 | Correct | 54 ms | 4576 KB | Output is correct |
15 | Correct | 38 ms | 3556 KB | Output is correct |
16 | Correct | 46 ms | 4960 KB | Output is correct |
17 | Correct | 54 ms | 5472 KB | Output is correct |
18 | Correct | 53 ms | 5472 KB | Output is correct |
19 | Correct | 61 ms | 5472 KB | Output is correct |
20 | Correct | 50 ms | 5472 KB | Output is correct |
21 | Correct | 58 ms | 5216 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 368 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 384 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 364 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 364 KB | Output is correct |
2 | Correct | 1 ms | 364 KB | Output is correct |
3 | Correct | 1 ms | 364 KB | Output is correct |
4 | Correct | 1 ms | 364 KB | Output is correct |
5 | Correct | 1 ms | 364 KB | Output is correct |
6 | Correct | 1 ms | 364 KB | Output is correct |
7 | Correct | 1 ms | 364 KB | Output is correct |
8 | Correct | 1 ms | 364 KB | Output is correct |
9 | Correct | 1 ms | 364 KB | Output is correct |
10 | Correct | 1 ms | 364 KB | Output is correct |
11 | Correct | 1 ms | 364 KB | Output is correct |
12 | Correct | 1 ms | 364 KB | Output is correct |
13 | Correct | 1 ms | 364 KB | Output is correct |
14 | Correct | 1 ms | 364 KB | Output is correct |
15 | Correct | 1 ms | 364 KB | Output is correct |
16 | Correct | 1 ms | 364 KB | Output is correct |
17 | Correct | 1 ms | 364 KB | Output is correct |
18 | Correct | 1 ms | 364 KB | Output is correct |
19 | Correct | 1 ms | 492 KB | Output is correct |
20 | Correct | 1 ms | 364 KB | Output is correct |
21 | Correct | 1 ms | 364 KB | Output is correct |
22 | Correct | 1 ms | 364 KB | Output is correct |
23 | Correct | 1 ms | 364 KB | Output is correct |
24 | Correct | 1 ms | 364 KB | Output is correct |
25 | Correct | 52 ms | 3936 KB | Output is correct |
26 | Correct | 83 ms | 4576 KB | Output is correct |
27 | Correct | 105 ms | 5088 KB | Output is correct |
28 | Correct | 105 ms | 5728 KB | Output is correct |
29 | Correct | 106 ms | 5600 KB | Output is correct |
30 | Correct | 59 ms | 3044 KB | Output is correct |
31 | Correct | 58 ms | 4832 KB | Output is correct |
32 | Correct | 80 ms | 5472 KB | Output is correct |
33 | Correct | 85 ms | 5344 KB | Output is correct |
34 | Correct | 86 ms | 5472 KB | Output is correct |
35 | Correct | 62 ms | 5472 KB | Output is correct |
36 | Correct | 87 ms | 5216 KB | Output is correct |
37 | Correct | 48 ms | 3936 KB | Output is correct |