Submission #927022

#TimeUsernameProblemLanguageResultExecution timeMemory
927022Gromp15Soccer (JOI17_soccer)C++17
35 / 100
1923 ms262144 KiB
#include <bits/stdc++.h> #define ll long long #define ar array #define db double #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); #define rint(l, r) uniform_int_distribution<int>(l, r)(rng) template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; } template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; } void test_case() { int h, w, a, b, c; cin >> h >> w >> a >> b >> c; int n; cin >> n; vector<ar<int, 2>> p(n); for (auto &x : p) cin >> x[0] >> x[1]; // dp[x][y] = min cost to have a player at (x, y) possessing the ball // after a player gets the ball and moves and kicks the ball, they will not move again const int dx[]{0, 1, -1, 0}, dy[]{1, 0, 0, -1}; auto in = [&](int x, int y) { return x >= 0 && y >= 0 && x <= h && y <= w; }; vector<vector<int>> dp2(h+1, vector<int>(w+1, 1e9)); { queue<ar<int, 2>> q; for (int i = 0; i < n; i++) { auto [x, y] = p[i]; dp2[x][y] = 0; q.push({x, y}); } while (q.size()) { auto [x, y] = q.front(); q.pop(); for (int d = 0; d < 4; d++) { int nx = x + dx[d], ny = y + dy[d]; if (!in(nx, ny)) continue; if (ckmin(dp2[nx][ny], dp2[x][y] + 1)) { q.push({nx, ny}); } } } } vector<vector<ll>> dp(h+1, vector<ll>(w+1, 1e18)); dp[p[0][0]][p[0][1]] = 0; priority_queue<ar<ll, 3>, vector<ar<ll, 3>>, greater<ar<ll, 3>>> q; q.push({0, p[0][0], p[0][1]}); while (q.size()) { auto [weight, x, y] = q.top(); q.pop(); if (weight != dp[x][y]) continue; // spread by walking for (int d = 0; d < 4; d++) { int nx = x + dx[d], ny = y + dy[d]; if (in(nx, ny) && ckmin(dp[nx][ny], dp[x][y] + c)) { q.push({dp[nx][ny], nx, ny}); } } // spread by kicking and having someone pick it up for (int d = 0; d < 4; d++) { for (int use = 1; use <= max(h, w); use++) { int nx = x + dx[d] * use, ny = y + dy[d] * use; if (!in(nx, ny)) break; if (ckmin(dp[nx][ny], dp[x][y] + (ll)dp2[nx][ny] * c + (ll)use * a + b)) { q.push({dp[nx][ny], nx, ny}); } } } } cout << dp[p[n-1][0]][p[n-1][1]] << '\n'; } int main() { cin.tie(0)->sync_with_stdio(0); int t = 1; // cin >> t; while (t--) test_case(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...