이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <cmath>
struct Point {
int x, y;
};
int calculateTotalDistance(const Point& eventLocation, const std::vector<Point>& participantLocations) {
int totalDistance = 0;
for (const auto& participant : participantLocations) {
int distance = std::abs(eventLocation.x - participant.x) + std::abs(eventLocation.y - participant.y);
totalDistance += distance;
}
return totalDistance;
}
Point findOptimalLocation(const std::vector<Point>& participantLocations) {
int minX = participantLocations[0].x;
int maxX = participantLocations[0].x;
int minY = participantLocations[0].y;
int maxY = participantLocations[0].y;
for (const auto& participant : participantLocations) {
minX = std::min(minX, participant.x);
maxX = std::max(maxX, participant.x);
minY = std::min(minY, participant.y);
maxY = std::max(maxY, participant.y);
}
int optimalX = (minX + maxX) / 2;
int optimalY = (minY + maxY) / 2;
return {optimalX, optimalY};
}
int main() {
int N;
std::cin >> N;
std::vector<Point> participantLocations(N);
for (int i = 0; i < N; i++) {
std::cin >> participantLocations[i].x >> participantLocations[i].y;
}
Point optimalLocation = findOptimalLocation(participantLocations);
int totalDistance = calculateTotalDistance(optimalLocation, participantLocations);
std::cout << "Optimal location: (" << optimalLocation.x << ", " << optimalLocation.y << ")" << std::endl;
std::cout << "Total distance: " << totalDistance << std::endl;
return 0;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |