Submission #999362

#TimeUsernameProblemLanguageResultExecution timeMemory
999362KatieBest Place (NOI17_bestplace)C++17
0 / 100
49 ms2896 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...