Submission #1084998

# Submission time Handle Problem Language Result Execution time Memory
1084998 2024-09-07T09:55:53 Z hahahaha Soccer (JOI17_soccer) C++17
100 / 100
308 ms 19904 KB
#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 time Memory Grader output
1 Correct 57 ms 13016 KB Output is correct
2 Correct 5 ms 11356 KB Output is correct
3 Correct 197 ms 17596 KB Output is correct
4 Correct 213 ms 17656 KB Output is correct
5 Correct 59 ms 11608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 226 ms 17608 KB Output is correct
2 Correct 221 ms 17624 KB Output is correct
3 Correct 171 ms 17680 KB Output is correct
4 Correct 162 ms 17604 KB Output is correct
5 Correct 163 ms 17616 KB Output is correct
6 Correct 181 ms 17596 KB Output is correct
7 Correct 194 ms 17648 KB Output is correct
8 Correct 197 ms 17628 KB Output is correct
9 Correct 220 ms 17812 KB Output is correct
10 Correct 38 ms 13036 KB Output is correct
11 Correct 194 ms 17652 KB Output is correct
12 Correct 204 ms 17624 KB Output is correct
13 Correct 132 ms 17740 KB Output is correct
14 Correct 201 ms 17648 KB Output is correct
15 Correct 162 ms 17652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 13016 KB Output is correct
2 Correct 5 ms 11356 KB Output is correct
3 Correct 197 ms 17596 KB Output is correct
4 Correct 213 ms 17656 KB Output is correct
5 Correct 59 ms 11608 KB Output is correct
6 Correct 226 ms 17608 KB Output is correct
7 Correct 221 ms 17624 KB Output is correct
8 Correct 171 ms 17680 KB Output is correct
9 Correct 162 ms 17604 KB Output is correct
10 Correct 163 ms 17616 KB Output is correct
11 Correct 181 ms 17596 KB Output is correct
12 Correct 194 ms 17648 KB Output is correct
13 Correct 197 ms 17628 KB Output is correct
14 Correct 220 ms 17812 KB Output is correct
15 Correct 38 ms 13036 KB Output is correct
16 Correct 194 ms 17652 KB Output is correct
17 Correct 204 ms 17624 KB Output is correct
18 Correct 132 ms 17740 KB Output is correct
19 Correct 201 ms 17648 KB Output is correct
20 Correct 162 ms 17652 KB Output is correct
21 Correct 68 ms 12380 KB Output is correct
22 Correct 308 ms 17608 KB Output is correct
23 Correct 250 ms 14560 KB Output is correct
24 Correct 304 ms 14836 KB Output is correct
25 Correct 239 ms 17608 KB Output is correct
26 Correct 293 ms 17916 KB Output is correct
27 Correct 152 ms 13272 KB Output is correct
28 Correct 182 ms 13892 KB Output is correct
29 Correct 266 ms 16724 KB Output is correct
30 Correct 169 ms 13656 KB Output is correct
31 Correct 219 ms 17652 KB Output is correct
32 Correct 283 ms 19904 KB Output is correct
33 Correct 194 ms 17600 KB Output is correct
34 Correct 285 ms 17904 KB Output is correct
35 Correct 158 ms 13816 KB Output is correct