# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1054213 | Adomas08 | Palembang Bridges (APIO15_bridge) | C++14 | 57 ms | 3480 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>
using namespace std;
int k, n;
int findmedian(vector<int> j){
j.erase(remove(j.begin(), j.end(), -1), j.end());
sort (j.begin(), j.end());
return (j[j.size() / 2] + j[j.size() / 2 - 1]) / 2;
}
int main(){
long long ans = 0, cur = 0, maxs = -1, ist, num = 0;
priority_queue <int> q;
int passed = 0;
int k, n;
cin >> k >> n;
int a[n*2];
vector <int> v;
char b[n], d[n];
int z[n];
ist = n;
for (int i = 0; i < n; i++){
z[i] = 0;
cin >> b[i] >> a[i*2] >> d[i] >> a[i*2+1];
if (b[i] == d[i]){
z[i] = 1;
ist--;
v.push_back(-1);
v.push_back(-1);
}
else {
v.push_back(a[i*2]);
v.push_back(a[i*2+1]);
}
if (a[i*2] > a[i*2+1]){
int temp = a[i*2];
a[i*2] = a[i*2+1];
a[i*2+1] = temp;
}
}
int f;
if (k == 1){
while (k--){
f = findmedian(v);
for (int i = 0; i < n; i++){
if (f >= a[i*2] && f <= a[i*2+1]){
v[i*2] = -1;
v[i*2+1] = -1;
}
}
}
for (int i = 0; i < n; i++){
if (b[i] == d[i]){
ans += a[i*2+1] - a[i*2];
}
else{
if (v[i*2] == -1){
ans += a[i*2+1] - a[i*2] + 1;
}
else{
if (f < a[i*2]) ans += 1 + a[i*2+1] - a[i*2] + 2 * (a[i*2] - f);
if (f > a[i*2+1]) ans += 1 + a[i*2+1] - a[i*2] + 2 * (f - a[i*2+1]);
}
}
}
}
else{
}
cout << ans;
}
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... |