# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1088447 | Sunbae | Palembang Bridges (APIO15_bridge) | C++17 | 35 ms | 4308 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |