# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
754074 |
2023-06-06T15:56:28 Z |
pavement |
Soccer (JOI17_soccer) |
C++17 |
|
899 ms |
209848 KB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define g0(a) get<0>(a)
#define g1(a) get<1>(a)
#define g2(a) get<2>(a)
#define g3(a) get<3>(a)
#define g4(a) get<4>(a)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
using db = double;
using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using iii = tuple<int, int, int>;
using iiii = tuple<int, int, int, int>;
using iiiii = tuple<int, int, int, int, int>;
template<class key, class value = null_type, class cmp = less<key> >
using ordered_set = tree<key, value, cmp, rb_tree_tag, tree_order_statistics_node_update>;
int H, W, N, sS, sT, eS, eT, dr[] = {-1, 0, 0, 1}, dc[] = {0, -1, 1, 0}, dist[1505][1505];
ll A, B, C, ans[1505][1505];
vector<iii> adj[1505][1505];
queue<iii> Q;
priority_queue<iii, vector<iii>, greater<iii> > pq;
main() {
ios::sync_with_stdio(0);
cin.tie(0);
cin >> H >> W >> A >> B >> C >> N;
H++;
W++;
for (int i = 1; i <= 3 * H; i++) {
for (int j = 1; j <= 3 * W; j++) {
dist[i][j] = ans[i][j] = (int)1e16;
}
}
for (int i = 1, S, T; i <= N; i++) {
cin >> S >> T;
S++;
T++;
if (dist[S][T]) {
dist[S][T] = 0;
Q.emplace(0, S, T);
}
if (i == 1) sS = S, sT = T;
else if (i == N) eS = S, eT = T;
}
while (!Q.empty()) {
auto [d, r, c] = Q.front();
Q.pop();
if (d != dist[r][c]) continue;
for (int k = 0; k < 4; k++) {
int nr = r + dr[k], nc = c + dc[k];
if (1 <= nr && nr <= H && 1 <= nc && nc <= W && dist[nr][nc] > d + 1) {
dist[nr][nc] = d + 1;
Q.emplace(d + 1, nr, nc);
}
}
}
for (int i = 1; i <= H; i++) {
for (int j = 1; j <= W; j++) {
for (int k = 0; k < 4; k++) {
int nr = i + dr[k], nc = j + dc[k];
if (1 <= nr && nr <= H && 1 <= nc && nc <= W) {
adj[i][j].eb(nr, nc, C);
}
}
adj[i][j].eb(H + i, j, B);
adj[H + i][j].eb(i, j, dist[i][j] * C);
adj[i][j].eb(2 * H + i, j, B);
adj[2 * H + i][j].eb(i, j, dist[i][j] * C);
adj[i][j].eb(i, W + j, B);
adj[i][W + j].eb(i, j, dist[i][j] * C);
adj[i][j].eb(i, 2 * W + j, B);
adj[i][2 * W + j].eb(i, j, dist[i][j] * C);
if (j > 1) adj[2 * H + i][j].eb(2 * H + i, j - 1, A);
if (j < W) adj[H + i][j].eb(H + i, j + 1, A);
if (i > 1) adj[i][2 * W + j].eb(i - 1, 2 * W + j, A);
if (i < H) adj[i][W + j].eb(i + 1, W + j, A);
}
}
ans[sS][sT] = 0;
pq.emplace(0, sS, sT);
while (!pq.empty()) {
auto [d, r, c] = pq.top();
pq.pop();
if (d != ans[r][c]) continue;
for (auto [nr, nc, w] : adj[r][c]) {
if (ans[nr][nc] > d + w) {
ans[nr][nc] = d + w;
pq.emplace(ans[nr][nc], nr, nc);
}
}
}
cout << ans[eS][eT] << '\n';
}
Compilation message
soccer.cpp:34:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
34 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
98288 KB |
Output is correct |
2 |
Correct |
29 ms |
53668 KB |
Output is correct |
3 |
Correct |
677 ms |
209076 KB |
Output is correct |
4 |
Correct |
661 ms |
209136 KB |
Output is correct |
5 |
Correct |
196 ms |
116872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
753 ms |
209052 KB |
Output is correct |
2 |
Correct |
757 ms |
209100 KB |
Output is correct |
3 |
Correct |
600 ms |
179308 KB |
Output is correct |
4 |
Correct |
543 ms |
209164 KB |
Output is correct |
5 |
Correct |
548 ms |
186412 KB |
Output is correct |
6 |
Correct |
617 ms |
209240 KB |
Output is correct |
7 |
Correct |
738 ms |
209220 KB |
Output is correct |
8 |
Correct |
668 ms |
209136 KB |
Output is correct |
9 |
Correct |
701 ms |
209084 KB |
Output is correct |
10 |
Correct |
133 ms |
91348 KB |
Output is correct |
11 |
Correct |
786 ms |
209156 KB |
Output is correct |
12 |
Correct |
757 ms |
209120 KB |
Output is correct |
13 |
Correct |
478 ms |
179412 KB |
Output is correct |
14 |
Correct |
720 ms |
209100 KB |
Output is correct |
15 |
Correct |
588 ms |
186420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
187 ms |
98288 KB |
Output is correct |
2 |
Correct |
29 ms |
53668 KB |
Output is correct |
3 |
Correct |
677 ms |
209076 KB |
Output is correct |
4 |
Correct |
661 ms |
209136 KB |
Output is correct |
5 |
Correct |
196 ms |
116872 KB |
Output is correct |
6 |
Correct |
753 ms |
209052 KB |
Output is correct |
7 |
Correct |
757 ms |
209100 KB |
Output is correct |
8 |
Correct |
600 ms |
179308 KB |
Output is correct |
9 |
Correct |
543 ms |
209164 KB |
Output is correct |
10 |
Correct |
548 ms |
186412 KB |
Output is correct |
11 |
Correct |
617 ms |
209240 KB |
Output is correct |
12 |
Correct |
738 ms |
209220 KB |
Output is correct |
13 |
Correct |
668 ms |
209136 KB |
Output is correct |
14 |
Correct |
701 ms |
209084 KB |
Output is correct |
15 |
Correct |
133 ms |
91348 KB |
Output is correct |
16 |
Correct |
786 ms |
209156 KB |
Output is correct |
17 |
Correct |
757 ms |
209120 KB |
Output is correct |
18 |
Correct |
478 ms |
179412 KB |
Output is correct |
19 |
Correct |
720 ms |
209100 KB |
Output is correct |
20 |
Correct |
588 ms |
186420 KB |
Output is correct |
21 |
Correct |
225 ms |
115092 KB |
Output is correct |
22 |
Correct |
837 ms |
209120 KB |
Output is correct |
23 |
Correct |
798 ms |
191100 KB |
Output is correct |
24 |
Correct |
899 ms |
206092 KB |
Output is correct |
25 |
Correct |
765 ms |
209188 KB |
Output is correct |
26 |
Correct |
825 ms |
209292 KB |
Output is correct |
27 |
Correct |
560 ms |
203776 KB |
Output is correct |
28 |
Correct |
619 ms |
203856 KB |
Output is correct |
29 |
Correct |
661 ms |
206880 KB |
Output is correct |
30 |
Correct |
619 ms |
203716 KB |
Output is correct |
31 |
Correct |
788 ms |
209156 KB |
Output is correct |
32 |
Correct |
864 ms |
209848 KB |
Output is correct |
33 |
Correct |
626 ms |
209060 KB |
Output is correct |
34 |
Correct |
891 ms |
209108 KB |
Output is correct |
35 |
Correct |
477 ms |
203744 KB |
Output is correct |