# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56559 | 2018-07-11T17:19:45 Z | leejseo | Palembang Bridges (APIO15_bridge) | C++ | 72 ms | 1808 KB |
#include <bits/stdc++.h> using namespace std; int K, N; void solve1(){ long long ans = 0; vector<int> L; int u, v; char x, y; for(int i=0; i<N; i++){ scanf("%c %d %c %d\n", &x, &u, &y, &v); if (x == y) ans += abs(u-v); else{ L.push_back(u); L.push_back(v); } } sort(L.begin(), L.end()); int M = L.size(); if (M == 0){ printf("%lld\n", ans); return; } long long mid = L[M/2]; for (int i=0; i<M; i++) ans += abs(L[i] - mid); ans += M/2; printf("%lld\n", ans); L.clear(); return; } void solve2(){ long long ans = 0; vector<int> L; int u, v; char x, y; for(int i=0; i<N; i++){ scanf("%c %d %c %d\n", &x, &u, &y, &v); if (x == y) ans += abs(u-v); else{ L.push_back(u); L.push_back(v); } } sort(L.begin(), L.end()); int M = L.size(); if (M == 0){ printf("%lld\n", ans); return; } long long cross = (int) 1e15; long long temp; for (int i=0; i<M; i++){ for (int j=0; j<i; j++){ long long b1 = L[i]; long long b2 = L[j]; temp = 0; for (int k=0; k<M; k++){ temp += min(abs(L[k]-b1), abs(L[k]-b2)); } cross = min(cross, temp); } } ans += cross; ans += M/2; printf("%lld\n", ans); return; } int main(void){ scanf("%d%d\n", &K, &N); if (K == 1) solve1(); else solve2(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | Output is correct |
2 | Correct | 2 ms | 376 KB | Output is correct |
3 | Correct | 2 ms | 376 KB | Output is correct |
4 | Correct | 2 ms | 432 KB | Output is correct |
5 | Correct | 3 ms | 616 KB | Output is correct |
6 | Correct | 3 ms | 616 KB | Output is correct |
7 | Correct | 3 ms | 616 KB | Output is correct |
8 | Correct | 3 ms | 616 KB | Output is correct |
9 | Correct | 3 ms | 616 KB | Output is correct |
10 | Correct | 2 ms | 616 KB | Output is correct |
11 | Correct | 3 ms | 660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 660 KB | Output is correct |
2 | Correct | 2 ms | 660 KB | Output is correct |
3 | Correct | 2 ms | 660 KB | Output is correct |
4 | Correct | 4 ms | 660 KB | Output is correct |
5 | Correct | 3 ms | 660 KB | Output is correct |
6 | Correct | 3 ms | 660 KB | Output is correct |
7 | Correct | 3 ms | 660 KB | Output is correct |
8 | Correct | 4 ms | 660 KB | Output is correct |
9 | Correct | 3 ms | 660 KB | Output is correct |
10 | Correct | 4 ms | 660 KB | Output is correct |
11 | Correct | 3 ms | 660 KB | Output is correct |
12 | Correct | 38 ms | 1764 KB | Output is correct |
13 | Correct | 63 ms | 1764 KB | Output is correct |
14 | Correct | 63 ms | 1768 KB | Output is correct |
15 | Correct | 48 ms | 1768 KB | Output is correct |
16 | Correct | 45 ms | 1768 KB | Output is correct |
17 | Correct | 59 ms | 1780 KB | Output is correct |
18 | Correct | 72 ms | 1808 KB | Output is correct |
19 | Correct | 72 ms | 1808 KB | Output is correct |
20 | Correct | 50 ms | 1808 KB | Output is correct |
21 | Correct | 66 ms | 1808 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1808 KB | Output is correct |
2 | Correct | 3 ms | 1808 KB | Output is correct |
3 | Incorrect | 11 ms | 1808 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1808 KB | Output is correct |
2 | Correct | 2 ms | 1808 KB | Output is correct |
3 | Incorrect | 16 ms | 1808 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1808 KB | Output is correct |
2 | Correct | 3 ms | 1808 KB | Output is correct |
3 | Incorrect | 15 ms | 1808 KB | Output isn't correct |
4 | Halted | 0 ms | 0 KB | - |