Submission #1084998

#TimeUsernameProblemLanguageResultExecution timeMemory
1084998hahahahaSoccer (JOI17_soccer)C++17
100 / 100
308 ms19904 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 505, mxN = 1e5 + 5; const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}; int n, m, k, A, B, C; int s[mxN], t[mxN], f[N][N]; long long d[N][N][5]; bool inside(int i, int j) { return 0 <= i && i <= n && 0 <= j && j <= m; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> m >> A >> B >> C >> k; memset(f, -1, sizeof(f)); queue<array<int, 2>> q; for (int i = 1; i <= k; ++i) { cin >> s[i] >> t[i]; f[s[i]][t[i]] = 0; q.push({s[i], t[i]}); } while (q.size()) { auto [u, v] = q.front(); q.pop(); for (int dr = 0; dr < 4; ++dr) { int x = u + dx[dr], y = v + dy[dr]; if (inside(x, y) && f[x][y] == -1) { f[x][y] = f[u][v] + 1; q.push({x, y}); } } } memset(d, 0x3f, sizeof(d)); using T = tuple<long long, int, int, int>; priority_queue<T, vector<T>, greater<T>> pq; auto psh = [&](int i, int j, int t, long long w) { if (inside(i, j) && d[i][j][t] > w) { pq.push({d[i][j][t] = w, i, j, t}); } }; psh(s[1], t[1], 4, 0); while (pq.size()) { auto [c, x, y, t] = pq.top(); pq.pop(); if (c != d[x][y][t]) { continue; } if (t == 4) { for (int dr = 0; dr < 4; ++dr) { int i = x + dx[dr], j = y + dy[dr]; psh(i, j, dr, c + B + A); psh(i, j, 4, c + C); } } else { psh(x + dx[t], y + dy[t], t, c + A); psh(x, y, 4, c + (long long) f[x][y] * C); } } cout << d[s[k]][t[k]][4]; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...