Submission #1270893

#TimeUsernameProblemLanguageResultExecution timeMemory
1270893tvgkSoccer (JOI17_soccer)C++20
100 / 100
361 ms23632 KiB
#include<bits/stdc++.h> using namespace std; #define task "a" #define se second #define fi first #define ll long long #define ii pair<ll, ll> #define tp tuple<ll, int, int, int> const long mxN = 5e2 + 7, inf = 1e9 + 7; const ll llinf = 1e18; int nRow, nCol, n, dis[mxN][mxN]; int d1[5] = {0, 0, 1, -1, 0}; int d2[5] = {0, 1, 0, 0, -1}; ll roll, shoot, run, mn[mxN][mxN][8]; priority_queue<tp, vector<tp>, greater<tp>> pq; bool Check(int u, int v) { return 0 <= u && u <= v; } void Dij() { while (pq.size()) { auto [cost, u, v, dir] = pq.top(); pq.pop(); if (cost != mn[u][v][dir]) continue; int p = u + d1[dir]; int q = v + d2[dir]; if (Check(p, nRow) && Check(q, nCol) && mn[p][q][dir] > cost + roll) { mn[p][q][dir] = cost + roll; pq.push({cost + roll, p, q, dir}); } if (mn[u][v][0] > cost + run * dis[u][v]) { mn[u][v][0] = cost + run * dis[u][v]; pq.push({mn[u][v][0], u, v, 0}); } if (!dir) { for (int i = 1; i <= 4; i++) { if (mn[u][v][i] > cost + shoot) { mn[u][v][i] = cost + shoot; pq.push({cost + shoot, u, v, i}); } int p = u + d1[i]; int q = v + d2[i]; if (Check(p, nRow) && Check(q, nCol) && mn[p][q][0] > cost + run) { mn[p][q][0] = cost + run; pq.push({cost + run, p, q, 0}); } } } } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); //freopen(task".INP", "r", stdin); //freopen(task".OUT", "w", stdout); cin >> nRow >> nCol; for (int i = 0; i <= nRow; i++) { for (int j = 0; j <= nCol; j++) { dis[i][j] = inf; for (int dir = 0; dir <= 4; dir++) mn[i][j][dir] = llinf; } } cin >> roll >> shoot >> run; cin >> n; ii en; for (int i = 1; i <= n; i++) { int u, v; cin >> u >> v; dis[u][v] = 0; if (i == 1) { pq.push({0, u, v, 0}); mn[u][v][0] = 0; } if (i == n) en = {u, v}; } for (int i = 1; i <= nRow; i++) { for (int j = 0; j <= nCol; j++) dis[i][j] = min(dis[i][j], dis[i - 1][j] + 1); } for (int i = nRow; i >= 0; i--) { for (int j = 0; j <= nCol; j++) { if (i != nRow) dis[i][j] = min(dis[i][j], dis[i + 1][j] + 1); } for (int j = 1; j <= nCol; j++) dis[i][j] = min(dis[i][j - 1] + 1, dis[i][j]); for (int j = nCol - 1; j >= 0; j--) dis[i][j] = min(dis[i][j + 1] + 1, dis[i][j]); } Dij(); cout << mn[en.fi][en.se][0]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...