제출 #861022

#제출 시각아이디문제언어결과실행 시간메모리
861022ratiBitaro's travel (JOI23_travel)C++14
5 / 100
3019 ms1116 KiB
#include <iostream> #include <vector> #include <algorithm> #include <cmath> using namespace std; int main() { int N; cin >> N; vector<int> sightseeing_spots(N); for (int i = 0; i < N; i++) { cin >> sightseeing_spots[i]; } int Q; cin >> Q; for (int q = 0; q < Q; q++) { int start_coordinate; cin >> start_coordinate; long long total_distance = 0; int current_position = start_coordinate; while (!sightseeing_spots.empty()) { int nearest_spot = sightseeing_spots[0]; int min_distance = abs(current_position - nearest_spot); for (int spot : sightseeing_spots) { int distance = abs(current_position - spot); if (distance < min_distance || (distance == min_distance && spot < nearest_spot)) { nearest_spot = spot; min_distance = distance; } } total_distance += min_distance; current_position = nearest_spot; // Remove the visited spot from the list sightseeing_spots.erase(find(sightseeing_spots.begin(), sightseeing_spots.end(), nearest_spot)); } cout << total_distance << 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...