제출 #1220679

#제출 시각아이디문제언어결과실행 시간메모리
1220679ml_tssSoccer (JOI17_soccer)C++20
35 / 100
31 ms18628 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, int>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int H, L;
    cin >> H >> L;
    int A, B, C;
    cin >> A >> B >> C;
    int N;
    cin >> N;
    vector<pair<int, int>> v(N);
    for (auto& [x, y] : v) cin >> x >> y;
    vector<vector<pii>> adj(N);
    for (int i = 0; i < N; i++) {
        int xi = v[i].first, yi = v[i].second;
        for (int j = 0; j < N; j++) {
            if (i == j) continue;
            int xj = v[j].first, yj = v[j].second;
            ll cost = LLONG_MAX;
            cost = min(cost, 1LL * C * (abs(xi - xj) + abs(yi - yj)));
            cost = min(cost, 1LL * A * abs(yi - yj) + B + 1LL * C * abs(xi - xj));
            cost = min(cost, 1LL * A * abs(xi - xj) + B + 1LL * C * abs(yi - yj));
            if (xi == xj) cost = min(cost, 1LL * A * abs(yi - yj) + B);
            if (yi == yj) cost = min(cost, 1LL * A * abs(xi - xj) + B);

            adj[i].emplace_back(cost, j);
        }
    }

    vector<ll> dist(N, LLONG_MAX);
    dist[0] = 0;
    priority_queue<pii, vector<pii>, greater<>> pq;
    pq.emplace(0, 0);
    while (!pq.empty()) {
        auto [d, u] = pq.top(); pq.pop();
        if (d > dist[u]) continue;
        for (auto [cost, v] : adj[u]) {
            if (dist[v] > dist[u] + cost) {
                dist[v] = dist[u] + cost;
                pq.emplace(dist[v], v);
            }
        }
    }

    cout << dist[N-1];
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...