# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
512689 | 2022-01-16T16:43:04 Z | LptN21 | Palembang Bridges (APIO15_bridge) | C++14 | 97 ms | 5684 KB |
#include <bits/stdc++.h> using namespace std; #define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); #define PI acos(-1.0) #define eps 1e-9 #define FF first #define SS second // VECTOR (6) #define pb push_back #define lb lower_bound #define ub upper_bound #define sz(v) int((v).size()) #define all(v) (v).begin(), (v).end() #define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() ); // BIT (6) #define CNTBIT(x) __builtin_popcountll(x) #define ODDBIT(x) __builtin_parityll(x) #define MASK(i) (1LL<<(i)) #define BIT(x, i) (((x)>>(i))&1) #define SUBSET(big, small) (((big)&(small))==(small)) #define MINBIT(x) (x)&(-x) //typedef typedef long long ll; typedef unsigned long long ull; typedef long double ld; typedef pair<int, int> ii; /* CODE BELOW */ const int N = 1e5 + 7, M = 1e9 + 7; const int oo = 1e9 + 7; const int MOD = 1e9 + 7; int n, m, k, t; ll p[N]; priority_queue<int> pqLeft; priority_queue<int, vector<int>, greater<int> > pqRight; ll leftSum = 0, rightSum = 0; void add(int p) { int med = (sz(pqLeft)?pqLeft.top():oo); if(p <= med) { pqLeft.push(p); leftSum+=p; } else { pqRight.push(p); rightSum+=p; } if(sz(pqRight)+1 < sz(pqLeft)) { int trans = pqLeft.top(); pqLeft.pop(), pqRight.push(trans); leftSum-=trans; rightSum+=trans; } else if(sz(pqRight) > sz(pqLeft)) { int trans = pqRight.top(); pqLeft.push(trans), pqRight.pop(); leftSum+=trans; rightSum-=trans; } } ll calc() {return rightSum - leftSum;} bool cmp(ii a, ii b) { return a.FF+a.SS<b.FF+b.SS; } signed main() { //freopen("test.inp", "r", stdin); //freopen("test.out", "w", stdout); //fastIO; scanf("%d%d\n", &k, &n); char chA[3], chB[3]; ll sameSide = 0; vector<ii> a; int x, y; for(int i=1;i<=n;i++) { scanf("%s%d%s%d\n", &chA, &x, &chB, &y); if(chA[0]!=chB[0]) a.pb(ii(x, y)); else sameSide+=abs(x - y); } sort(all(a), cmp); n = sz(a); sameSide+=n; for(int i=1;i<=n;i++) { add(a[i-1].FF); add(a[i-1].SS); p[i] = calc(); } ll ans = p[n]; if(k==2) { while(sz(pqLeft)) pqLeft.pop(); while(sz(pqRight)) pqRight.pop(); leftSum = rightSum = 0; for(int i=n;i>0;i--) { add(a[i-1].FF); add(a[i-1].SS); ans = min(ans, p[i-1] + calc()); } } printf("%lld", ans + sameSide); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 2 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 332 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 332 KB | Output is correct |
10 | Correct | 1 ms | 328 KB | Output is correct |
11 | Correct | 1 ms | 332 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 332 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 332 KB | Output is correct |
6 | Correct | 1 ms | 332 KB | Output is correct |
7 | Correct | 1 ms | 316 KB | Output is correct |
8 | Correct | 1 ms | 332 KB | Output is correct |
9 | Correct | 1 ms | 336 KB | Output is correct |
10 | Correct | 1 ms | 332 KB | Output is correct |
11 | Correct | 2 ms | 332 KB | Output is correct |
12 | Correct | 37 ms | 4176 KB | Output is correct |
13 | Correct | 58 ms | 5556 KB | Output is correct |
14 | Correct | 49 ms | 4272 KB | Output is correct |
15 | Correct | 35 ms | 3432 KB | Output is correct |
16 | Correct | 40 ms | 4784 KB | Output is correct |
17 | Correct | 50 ms | 5312 KB | Output is correct |
18 | Correct | 47 ms | 4984 KB | Output is correct |
19 | Correct | 52 ms | 5344 KB | Output is correct |
20 | Correct | 44 ms | 5336 KB | Output is correct |
21 | Correct | 54 ms | 5132 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 304 KB | Output is correct |
3 | Correct | 1 ms | 304 KB | Output is correct |
4 | Correct | 1 ms | 304 KB | Output is correct |
5 | Correct | 0 ms | 304 KB | Output is correct |
6 | Correct | 0 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 0 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 204 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 1 ms | 204 KB | Output is correct |
4 | Correct | 1 ms | 332 KB | Output is correct |
5 | Correct | 1 ms | 204 KB | Output is correct |
6 | Correct | 1 ms | 204 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 0 ms | 204 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 1 ms | 204 KB | Output is correct |
11 | Correct | 0 ms | 204 KB | Output is correct |
12 | Correct | 0 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 332 KB | Output is correct |
14 | Correct | 1 ms | 312 KB | Output is correct |
15 | Correct | 1 ms | 332 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 308 KB | Output is correct |
18 | Correct | 1 ms | 304 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 320 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 316 KB | Output is correct |
24 | Correct | 1 ms | 320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 280 KB | Output is correct |
2 | Correct | 0 ms | 204 KB | Output is correct |
3 | Correct | 0 ms | 216 KB | Output is correct |
4 | Correct | 0 ms | 216 KB | Output is correct |
5 | Correct | 0 ms | 212 KB | Output is correct |
6 | Correct | 0 ms | 208 KB | Output is correct |
7 | Correct | 0 ms | 204 KB | Output is correct |
8 | Correct | 1 ms | 300 KB | Output is correct |
9 | Correct | 1 ms | 204 KB | Output is correct |
10 | Correct | 0 ms | 204 KB | Output is correct |
11 | Correct | 1 ms | 204 KB | Output is correct |
12 | Correct | 1 ms | 204 KB | Output is correct |
13 | Correct | 1 ms | 308 KB | Output is correct |
14 | Correct | 1 ms | 332 KB | Output is correct |
15 | Correct | 1 ms | 336 KB | Output is correct |
16 | Correct | 1 ms | 204 KB | Output is correct |
17 | Correct | 1 ms | 308 KB | Output is correct |
18 | Correct | 1 ms | 204 KB | Output is correct |
19 | Correct | 1 ms | 332 KB | Output is correct |
20 | Correct | 1 ms | 332 KB | Output is correct |
21 | Correct | 1 ms | 340 KB | Output is correct |
22 | Correct | 1 ms | 332 KB | Output is correct |
23 | Correct | 1 ms | 332 KB | Output is correct |
24 | Correct | 1 ms | 332 KB | Output is correct |
25 | Correct | 44 ms | 3872 KB | Output is correct |
26 | Correct | 68 ms | 4268 KB | Output is correct |
27 | Correct | 90 ms | 5076 KB | Output is correct |
28 | Correct | 92 ms | 5684 KB | Output is correct |
29 | Correct | 97 ms | 5348 KB | Output is correct |
30 | Correct | 47 ms | 2992 KB | Output is correct |
31 | Correct | 47 ms | 4720 KB | Output is correct |
32 | Correct | 68 ms | 5404 KB | Output is correct |
33 | Correct | 78 ms | 5368 KB | Output is correct |
34 | Correct | 75 ms | 5300 KB | Output is correct |
35 | Correct | 55 ms | 5440 KB | Output is correct |
36 | Correct | 76 ms | 5168 KB | Output is correct |
37 | Correct | 38 ms | 3764 KB | Output is correct |