# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088447 | 2024-09-14T12:11:12 Z | Sunbae | Palembang Bridges (APIO15_bridge) | C++17 | 35 ms | 4308 KB |
#include <bits/stdc++.h> typedef long long ll; using namespace std; int a[200000], P[100000][2]; bool ok[100000]; signed main(){ int k, n, m = 0; scanf("%d %d", &k, &n); ll tot = 0, s[2] = {0, 0}; for(int i = 0; i<n; ++i){ char c[2]; int p[2]; scanf(" %c %d %c %d", c, p, c+1, p+1); if(c[0] == c[1]) tot += abs(p[0]-p[1]); else {a[m++] = p[0]; a[m++] = p[1]; ok[i] = true;} P[i][0] = p[0]; P[i][1] = p[1]; } sort(a, a+m); if(k == 1){ for(int j = 0; j<2; ++j) for(int i = 0; i<m; ++i) s[j] += abs(a[i] - a[m/2 - j]); printf("%lld", tot + min(s[0], s[1]) + m/2); }else{ for(int i = 0; i<n; ++i){ if(ok[i]){ ll o[2] = {0, 0}; for(int j = 0; j<2; ++j) o[j] = (ll)abs(P[i][0] - a[m/2 - j]) + (ll)abs(P[i][1] - a[m/2 - j]); tot += min(o[0], o[1]); } } printf("%lld", tot + m/2); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 484 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 1 ms | 344 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 1 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 348 KB | Output is correct |
4 | Correct | 1 ms | 348 KB | Output is correct |
5 | Correct | 1 ms | 348 KB | Output is correct |
6 | Correct | 1 ms | 344 KB | Output is correct |
7 | Correct | 1 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 348 KB | Output is correct |
10 | Correct | 0 ms | 452 KB | Output is correct |
11 | Correct | 1 ms | 348 KB | Output is correct |
12 | Correct | 18 ms | 2676 KB | Output is correct |
13 | Correct | 35 ms | 4308 KB | Output is correct |
14 | Correct | 25 ms | 2904 KB | Output is correct |
15 | Correct | 20 ms | 2796 KB | Output is correct |
16 | Correct | 21 ms | 3580 KB | Output is correct |
17 | Correct | 23 ms | 4260 KB | Output is correct |
18 | Correct | 28 ms | 3924 KB | Output is correct |
19 | Correct | 32 ms | 4184 KB | Output is correct |
20 | Correct | 24 ms | 3932 KB | Output is correct |
21 | Correct | 28 ms | 3928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Incorrect | 0 ms | 348 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |