Submission #882952

# Submission time Handle Problem Language Result Execution time Memory
882952 2023-12-04T08:59:31 Z DAleksa Soccer (JOI17_soccer) C++17
100 / 100
590 ms 115636 KB
#include <bits/stdc++.h>

using namespace std;

struct node {
    int v;
    long long w;
};

const int N = 1e5 + 20, M = 501;
int H, W;
long long A, B, C;
int n;
int x[N], y[N];

int f(int i, int j, int k) { return i * M * 3 + j * 3 + k; }

int bfsdist[M][M];
bool bfsmark[M][M];

vector<node> g[M * M * 3];
long long dist[M * M * 3];
set<pair<long long, int>> s;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> H >> W >> A >> B >> C >> n;
    for(int i = 0; i <= H; i++) for(int j = 0; j <= W; j++) bfsdist[i][j] = 1e9;
    queue<pair<int, int>> q;
    for(int i = 0; i < n; i++) {
        cin >> x[i] >> y[i];
        bfsdist[x[i]][y[i]] = 0;
        q.push({x[i], y[i]});
        bfsmark[x[i]][y[i]] = true;
    }
    while(!q.empty()) {
        pair<int, int> p = q.front();
        q.pop();
        int i = p.first, j = p.second;
        for(int di = -1; di <= 1; di++) {
            for(int dj = -1; dj <= 1; dj++) {
                if(di == 0 && dj == 0) continue;
                if(di != 0 && dj != 0) continue;
                if(i + di < 0 || i + di > H || j + dj < 0 || j + dj > W) continue;
                if(bfsmark[i + di][j + dj]) continue;
                bfsmark[i + di][j + dj] = true;
                bfsdist[i + di][j + dj] = bfsdist[i][j] + 1;
                q.push({i + di, j + dj});
            }
        }
    }
    for(int i = 0; i <= H; i++) {
        for(int j = 0; j <= W; j++) {
            if(i + 1 <= H) {
                g[f(i, j, 2)].push_back({f(i + 1, j, 2), C});
                g[f(i + 1, j, 2)].push_back({f(i, j, 2), C});
                g[f(i, j, 0)].push_back({f(i + 1, j, 0), A});
                g[f(i + 1, j, 0)].push_back({f(i, j, 0), A});
            }
            if(j + 1 <= W) {
                g[f(i, j, 2)].push_back({f(i, j + 1, 2), C});
                g[f(i, j + 1, 2)].push_back({f(i, j, 2), C});
                g[f(i, j, 1)].push_back({f(i, j + 1, 1), A});
                g[f(i, j + 1, 1)].push_back({f(i, j, 1), A});
            }
            g[f(i, j, 2)].push_back({f(i, j, 0), B});
            g[f(i, j, 2)].push_back({f(i, j, 1), B});
            g[f(i, j, 0)].push_back({f(i, j, 2), C * 1LL * bfsdist[i][j]});
            g[f(i, j, 1)].push_back({f(i, j, 2), C * 1LL * bfsdist[i][j]});
        }
    }
    for(int i = 0; i <= H; i++) for(int j = 0; j <= W; j++) for(int k = 0; k < 3; k++) dist[f(i, j, k)] = 1e18;
    dist[f(x[0], y[0], 2)] = 0;
    s.insert({0, f(x[0], y[0], 2)});
    while(!s.empty()) {
        pair<long long, int> p = *s.begin();
        s.erase(s.begin());
        long long d = p.first;
        int u = p.second;
        for(node v : g[u]) {
            if(dist[u] + v.w < dist[v.v]) {
                dist[v.v] = dist[u] + v.w;
                s.insert({dist[v.v], v.v});
            }
        }
    }
    cout << min({dist[f(x[n - 1], y[n - 1], 0)], dist[f(x[n - 1], y[n - 1], 1)], dist[f(x[n - 1], y[n - 1], 2)]});
    return 0;
}

Compilation message

soccer.cpp: In function 'int main()':
soccer.cpp:79:19: warning: unused variable 'd' [-Wunused-variable]
   79 |         long long d = p.first;
      |                   ^
# Verdict Execution time Memory Grader output
1 Correct 97 ms 45652 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 432 ms 110012 KB Output is correct
4 Correct 464 ms 111308 KB Output is correct
5 Correct 78 ms 52556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 411 ms 113800 KB Output is correct
2 Correct 431 ms 114488 KB Output is correct
3 Correct 316 ms 95188 KB Output is correct
4 Correct 264 ms 108260 KB Output is correct
5 Correct 329 ms 95312 KB Output is correct
6 Correct 293 ms 111996 KB Output is correct
7 Correct 479 ms 115288 KB Output is correct
8 Correct 384 ms 115292 KB Output is correct
9 Correct 442 ms 115272 KB Output is correct
10 Correct 57 ms 39564 KB Output is correct
11 Correct 434 ms 115440 KB Output is correct
12 Correct 437 ms 115000 KB Output is correct
13 Correct 252 ms 95680 KB Output is correct
14 Correct 419 ms 115520 KB Output is correct
15 Correct 349 ms 97360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 97 ms 45652 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 432 ms 110012 KB Output is correct
4 Correct 464 ms 111308 KB Output is correct
5 Correct 78 ms 52556 KB Output is correct
6 Correct 411 ms 113800 KB Output is correct
7 Correct 431 ms 114488 KB Output is correct
8 Correct 316 ms 95188 KB Output is correct
9 Correct 264 ms 108260 KB Output is correct
10 Correct 329 ms 95312 KB Output is correct
11 Correct 293 ms 111996 KB Output is correct
12 Correct 479 ms 115288 KB Output is correct
13 Correct 384 ms 115292 KB Output is correct
14 Correct 442 ms 115272 KB Output is correct
15 Correct 57 ms 39564 KB Output is correct
16 Correct 434 ms 115440 KB Output is correct
17 Correct 437 ms 115000 KB Output is correct
18 Correct 252 ms 95680 KB Output is correct
19 Correct 419 ms 115520 KB Output is correct
20 Correct 349 ms 97360 KB Output is correct
21 Correct 96 ms 52492 KB Output is correct
22 Correct 531 ms 108732 KB Output is correct
23 Correct 509 ms 100436 KB Output is correct
24 Correct 576 ms 106576 KB Output is correct
25 Correct 518 ms 112136 KB Output is correct
26 Correct 476 ms 108620 KB Output is correct
27 Correct 286 ms 100996 KB Output is correct
28 Correct 303 ms 101460 KB Output is correct
29 Correct 429 ms 107004 KB Output is correct
30 Correct 279 ms 101412 KB Output is correct
31 Correct 480 ms 115636 KB Output is correct
32 Correct 584 ms 115592 KB Output is correct
33 Correct 356 ms 111996 KB Output is correct
34 Correct 590 ms 112832 KB Output is correct
35 Correct 240 ms 101460 KB Output is correct