Submission #868657

# Submission time Handle Problem Language Result Execution time Memory
868657 2023-11-01T06:07:47 Z Desh03 Soccer (JOI17_soccer) C++17
35 / 100
1747 ms 262144 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

soccer.cpp: In function 'int main()':
soccer.cpp:46:23: warning: 'dsty' may be used uninitialized in this function [-Wmaybe-uninitialized]
   46 |         if (x == dstx && y == dsty) {
      |             ~~~~~~~~~~^~~~~~~~~~~~
soccer.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 Correct 16 ms 2256 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 70 ms 7960 KB Output is correct
4 Correct 20 ms 5580 KB Output is correct
5 Correct 112 ms 2516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 5588 KB Output is correct
2 Correct 9 ms 4552 KB Output is correct
3 Correct 100 ms 7468 KB Output is correct
4 Correct 647 ms 9268 KB Output is correct
5 Correct 110 ms 11344 KB Output is correct
6 Correct 204 ms 8140 KB Output is correct
7 Correct 14 ms 8652 KB Output is correct
8 Correct 17 ms 9184 KB Output is correct
9 Correct 12 ms 5584 KB Output is correct
10 Correct 12 ms 2024 KB Output is correct
11 Correct 33 ms 13860 KB Output is correct
12 Correct 55 ms 12244 KB Output is correct
13 Correct 126 ms 8392 KB Output is correct
14 Correct 15 ms 8396 KB Output is correct
15 Correct 7 ms 4048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 2256 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 70 ms 7960 KB Output is correct
4 Correct 20 ms 5580 KB Output is correct
5 Correct 112 ms 2516 KB Output is correct
6 Correct 16 ms 5588 KB Output is correct
7 Correct 9 ms 4552 KB Output is correct
8 Correct 100 ms 7468 KB Output is correct
9 Correct 647 ms 9268 KB Output is correct
10 Correct 110 ms 11344 KB Output is correct
11 Correct 204 ms 8140 KB Output is correct
12 Correct 14 ms 8652 KB Output is correct
13 Correct 17 ms 9184 KB Output is correct
14 Correct 12 ms 5584 KB Output is correct
15 Correct 12 ms 2024 KB Output is correct
16 Correct 33 ms 13860 KB Output is correct
17 Correct 55 ms 12244 KB Output is correct
18 Correct 126 ms 8392 KB Output is correct
19 Correct 15 ms 8396 KB Output is correct
20 Correct 7 ms 4048 KB Output is correct
21 Correct 49 ms 2512 KB Output is correct
22 Correct 380 ms 12236 KB Output is correct
23 Correct 441 ms 20396 KB Output is correct
24 Correct 297 ms 12276 KB Output is correct
25 Correct 271 ms 21760 KB Output is correct
26 Correct 450 ms 21936 KB Output is correct
27 Correct 408 ms 9616 KB Output is correct
28 Correct 884 ms 14748 KB Output is correct
29 Correct 1747 ms 136836 KB Output is correct
30 Runtime error 959 ms 262144 KB Execution killed with signal 9
31 Halted 0 ms 0 KB -