이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
int main() {
cin >> K >> N;
for (int i = 0; i < N; i++) {
cin >> zone1 >> build1 >> zone2 >> build2;
if (zone1 == zone2) {
Dmin += build2 - build1;
} else {
people.push_back(make_pair(
(Place){zone1, build1},
(Place){zone2, build2}
));
}
}
int M = people.size();
long long int possibleMin = INF;
for (int i = 0; i < M; i++) {
long long int currK = people[i].first.building;
long long int currMin = 0;
for (int j = 0; j < M; j++) {
currMin += abs(people[j].first.building - currK);
currMin++;
currMin += abs(people[j].second.building - currK);
}
possibleMin = min(currMin, possibleMin);
}
cout << possibleMin + Dmin << "\n";
}
# | 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... |