# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
640803 | 2022-09-15T09:30:11 Z | Son | Palembang Bridges (APIO15_bridge) | C++14 | 89 ms | 6724 KB |
#include <bits/stdc++.h> using namespace std; #define LL long long #define pb push_back #define mp make_pair #define fi first #define se second int K,N; char Ax[10], Bx[10]; int A[100005], B[100005]; vector < int > V; LL lsum = 0, rsum = 0; LL P[100005], S[100005]; priority_queue < int > lpq; priority_queue < int , vector < int > , greater < int > > rpq; bool cmp( int a, int b ){ return A[a] + B[a] < A[b] + B[b]; } void reset(){ lsum = rsum = 0; while ( !lpq.empty() ) lpq.pop(); while ( !rpq.empty() ) rpq.pop(); } void add( int x ){ if ( lpq.empty() || x <= lpq.top() ){ lpq.push(x); lsum += x; } else { rpq.push(x); rsum += x; } if ( rpq.size() + 1 < lpq.size() ){ int y = lpq.top(); lpq.pop(); rpq.push(y); lsum -= y; rsum += y; } else if ( lpq.size() < rpq.size() ){ int y = rpq.top(); rpq.pop(); lpq.push(y); rsum -= y; lsum += y; } } int main(){ LL ss = 0, bridges = 0; scanf("%d%d",&K,&N); for ( int i = 1; i <= N; i++ ){ scanf("%s%d%s%d",&Ax,&A[i],&Bx,&B[i]); if ( A[i] > B[i] ){ swap(A[i],B[i]); } if ( Ax[0] == Bx[0] ){ ss += B[i] - A[i]; } else { bridges += 1; V.push_back(i); } } sort(V.begin(),V.end(),cmp); reset(); for ( int i = 0; i < V.size(); i++ ){ int id = V[i]; add(A[id]); add(B[id]); P[i] = rsum - lsum; } reset(); for ( int i = V.size()-1; i >= 0; i-- ){ int id = V[i]; add(A[id]); add(B[id]); S[i] = rsum - lsum; } LL ans = P[V.size()-1] + ss + bridges; for ( int i = 0; i < V.size() && K == 2; i++ ){ LL temp = ss + bridges + S[i]; if ( i ) temp += P[i-1]; if ( temp < ans ) ans = temp; } printf("%lld\n",ans); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | 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 | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 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 | 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 | 340 KB | Output is correct |
5 | Correct | 1 ms | 340 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 | 340 KB | Output is correct |
11 | Correct | 1 ms | 340 KB | Output is correct |
12 | Correct | 37 ms | 4256 KB | Output is correct |
13 | Correct | 89 ms | 4052 KB | Output is correct |
14 | Correct | 71 ms | 3684 KB | Output is correct |
15 | Correct | 47 ms | 2404 KB | Output is correct |
16 | Correct | 35 ms | 4164 KB | Output is correct |
17 | Correct | 72 ms | 4276 KB | Output is correct |
18 | Correct | 50 ms | 4084 KB | Output is correct |
19 | Correct | 76 ms | 4164 KB | Output is correct |
20 | Correct | 49 ms | 3872 KB | Output is correct |
21 | Correct | 73 ms | 4284 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 | 1 ms | 212 KB | Output is correct |
8 | Correct | 1 ms | 316 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 |
# | 결과 | 실행 시간 | 메모리 | 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 | 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 | 0 ms | 212 KB | Output is correct |
8 | Correct | 0 ms | 212 KB | Output is correct |
9 | Correct | 1 ms | 212 KB | Output is correct |
10 | Correct | 0 ms | 340 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 | 1 ms | 340 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 468 KB | Output is correct |
20 | Correct | 2 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 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 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 | 316 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 | 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 | 320 KB | Output is correct |
11 | Correct | 1 ms | 312 KB | Output is correct |
12 | Correct | 0 ms | 212 KB | Output is correct |
13 | Correct | 1 ms | 316 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 | 312 KB | Output is correct |
17 | Correct | 1 ms | 340 KB | Output is correct |
18 | Correct | 1 ms | 340 KB | Output is correct |
19 | Correct | 1 ms | 324 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 | 38 ms | 5064 KB | Output is correct |
26 | Correct | 61 ms | 5064 KB | Output is correct |
27 | Correct | 83 ms | 5608 KB | Output is correct |
28 | Correct | 85 ms | 6272 KB | Output is correct |
29 | Correct | 82 ms | 6224 KB | Output is correct |
30 | Correct | 43 ms | 3656 KB | Output is correct |
31 | Correct | 37 ms | 5828 KB | Output is correct |
32 | Correct | 67 ms | 6500 KB | Output is correct |
33 | Correct | 50 ms | 6144 KB | Output is correct |
34 | Correct | 81 ms | 6724 KB | Output is correct |
35 | Correct | 50 ms | 5780 KB | Output is correct |
36 | Correct | 72 ms | 6288 KB | Output is correct |
37 | Correct | 37 ms | 4968 KB | Output is correct |