# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1016966 | TroySer | Palembang Bridges (APIO15_bridge) | C++17 | 73 ms | 10076 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.
// median?
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;
long long int K, N;
long long int build1, build2;
char zone1, zone2;
long long int Dmin = 0;
struct Place {
char zone;
long long int building;
};
vector<pair<Place, Place> > people;
vector<long long int> person;
long long int cost(long long int currK) {
long long int currMin = 0;
for (int j = 0; j < people.size(); j++) {
currMin += abs(people[j].first.building - currK);
currMin++;
currMin += abs(people[j].second.building - currK);
}
return currMin;
}
int main() {
cin >> K >> N;
for (int i = 0; i < N; i++) {
cin >> zone1 >> build1 >> zone2 >> build2;
if (zone1 == zone2) {
Dmin += abs(build2 - build1);
} else {
people.push_back(make_pair(
(Place){zone1, build1},
(Place){zone2, build2}
));
person.push_back(build1);
person.push_back(build2);
}
}
int M = person.size();
long long int possibleMin = INF;
if (M == 0) possibleMin = 0;
else {
sort(person.begin(), person.end());
for (int i = M/2; i <= M/2 + 1; i++) {
possibleMin = min(possibleMin, cost(person[i]));
}
}
cout << possibleMin + Dmin << "\n";
}
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... |