답안 #861024

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
861024 2023-10-15T06:53:41 Z rati Bitaro's travel (JOI23_travel) C++14
0 / 100
0 ms 344 KB
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <limits>

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;

        vector<long long> distance(N, numeric_limits<long long>::max());
        set<pair<long long, int>> pq;

        for (int i = 0; i < N; i++) {
            long long d = abs(start_coordinate - sightseeing_spots[i]);
            pq.insert({d, i});
            distance[i] = d;
        }

        long long total_distance = 0;

        while (!pq.empty()) {
            int i = pq.begin()->second;
            long long d = pq.begin()->first;
            pq.erase(pq.begin());

            if (d > distance[i]) {
                continue;
            }

            total_distance += d;

            for (int j = 0; j < N; j++) {
                if (i != j) {
                    long long new_distance = abs(sightseeing_spots[i] - sightseeing_spots[j]);
                    if (new_distance < distance[j]) {
                        pq.erase({distance[j], j});
                        distance[j] = new_distance;
                        pq.insert({distance[j], j});
                    }
                }
            }
        }

        cout << total_distance << endl;
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -