Submission #868655

# Submission time Handle Problem Language Result Execution time Memory
868655 2023-11-01T06:05:17 Z Desh03 Self Study (JOI22_ho_t2) C++17
0 / 100
1 ms 348 KB
#include <bits/stdc++.h>

using namespace std;

const long long INF = 1e18;

vector<pair<int, int>> dxdy = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int h, w, a, b, c, n;
    cin >> h >> w >> a >> b >> c >> n;
    vector f(h + 1, vector<int> (w + 1, 1e9));
    vector d(h + 1, vector<long long> (w + 1, INF));
    int srcx, srcy, dstx, dsty;
    queue<pair<int, int>> q;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        if (i == 0) srcx = x, srcy = y;
        if (i == n - 1) dstx = x, dsty = y;
        if (f[x][y]) q.push({x, y});
        f[x][y] = 0;
    }
    auto valid = [&](int x, int y) {
        return x >= 0 && y >= 0 && x <= h && y <= w;
    };
    while (q.size()) {
        auto [x, y] = q.front();
        q.pop();
        for (auto [dx, dy] : dxdy) {
            if (!valid(x + dx, y + dy)) continue;
            if (f[x][y] + 1 < f[x + dx][y + dy]) {
                f[x + dx][y + dy] = f[x][y] + 1;
                q.push({x + dx, y + dy});
            }
        }
    }
    vector vis(h + 1, vector<bool> (w + 1));
    priority_queue<tuple<long long, int, int>, vector<tuple<long long, int, int>>, greater<tuple<long long, int, int>>> pq;
    pq.push({d[srcx][srcy] = 0, srcx, srcy});
    while (pq.size()) {
        auto [W, x, y] = pq.top();
        pq.pop();
        if (x == dstx && y == dsty) {
            cout << W << '\n';
            return 0;
        }
        if (vis[x][y]) continue;
        vis[x][y] = 1;
        for (int i = 0; i <= h; i++) {
            int dst = abs(x - i);
            long long cst = min((long long) dst * c, (long long) dst * a + b + (long long) c * f[i][y]);
            if (W + cst < d[i][y]) {
                pq.push({d[i][y] = W + cst, i, y});
            }
        }
        for (int i = 0; i <= w; i++) {
            int dst = abs(y - i);
            long long cst = min((long long) dst * c, (long long) dst * a + b + (long long) c * f[x][i]);
            if (W + cst < d[x][i]) {
                pq.push({d[x][i] = W + cst, x, i});
            }
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:46:23: warning: 'dsty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |         if (x == dstx && y == dsty) {
      |             ~~~~~~~~~~^~~~~~~~~~~~
Main.cpp:46:9: warning: 'dstx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |         if (x == dstx && y == dsty) {
      |         ^~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -