# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
291918 |
2020-09-06T02:43:49 Z |
anonymous |
Soccer (JOI17_soccer) |
C++14 |
|
669 ms |
40564 KB |
#include <iostream>
#include <queue>
#include <utility>
#define MAXD 505
#define MAXN 100005
#define LL long long
using namespace std;
int W, H, N, P[MAXN][2];
LL A, B, C, dist[MAXD][MAXD][6], closest[MAXD][MAXD];
int Dy[4] = {1,0,-1,0}, Dx[4] = {0,1,0,-1};
bool okay(int x, int y) {
return(x >= 0 && y >= 0 && x <= H && y <= W);
}
struct state {
int x, y, type; //still, dribble, up, down, right, left
LL dist;
};
class CompareClass {
public:
bool operator() (state a, state b) {
return(a.dist > b.dist); //smallest first
}
};
priority_queue <state, vector<state>, CompareClass> PQ;
void gendist() {
queue <pair<int,int> > Q;
for (int i=0; i <= H; i++) {
for (int j=0; j <= W; j++) {
closest[i][j] = 1LL << 60;
}
}
for (int i=1; i<=N; i++) {
Q.push({P[i][0], P[i][1]});
closest[P[i][0]][P[i][1]] = 0;
}
while (Q.size()) {
int cx = Q.front().first, cy = Q.front().second;
Q.pop();
for (int i=0; i<4; i++) {
if (okay(cx + Dx[i], cy + Dy[i]) && closest[cx+Dx[i]][cy + Dy[i]] > closest[cx][cy]+C) {
closest[cx+Dx[i]][cy + Dy[i]] = closest[cx][cy]+C;
Q.push({cx+Dx[i], cy+Dy[i]});
}
}
}
}
void relax(int x, int y, int type, LL d) {
if (dist[x][y][type] > d) {
dist[x][y][type] = d;
PQ.push(state {x,y,type, d});
}
}
int main() {
//freopen("soccerin.txt","r",stdin);
scanf("%d %d\n%lld %lld %lld\n%d",&H,&W,&A,&B,&C,&N);
for (int i=1; i<=N; i++) {
scanf("%d %d",&P[i][0], &P[i][1]);
}
gendist();
PQ.push(state {P[1][0], P[1][1], 0, 0});
for (int i=0; i <= H; i++) {
for (int j=0; j <= W; j++) {
for (int k=0; k<6; k++) {
dist[i][j][k] = 1LL << 60;
}
}
}
dist[P[1][0]][P[1][1]][0] = 0;
while (PQ.size()) {
state cur = PQ.top();
PQ.pop();
if (cur.x == P[N][0] && cur.y == P[N][1]) {
printf("%lld",cur.dist);
return(0);
}
if (cur.dist != dist[cur.x][cur.y][cur.type]) {continue;}
if (cur.type == 0) {
relax(cur.x, cur.y, 1, cur.dist + closest[cur.x][cur.y]);
for (int i=2; i <= 5; i++) {
relax(cur.x,cur.y, i, cur.dist + closest[cur.x][cur.y] + B);
}
} else if (cur.type == 1) {
relax(cur.x, cur.y, 0, cur.dist);
for (int i=2; i <= 5; i++) {
relax(cur.x,cur.y, i, cur.dist + B);
}
for (int i=0; i<4; i++) {
if (okay(cur.x + Dx[i], cur.y + Dy[i])) {
relax(cur.x + Dx[i], cur.y + Dy[i], 1, cur.dist + C);
}
}
} else {
relax(cur.x, cur.y, 0, cur.dist);
if (okay(cur.x + Dx[cur.type - 2], cur.y + Dy[cur.type - 2])) {
relax(cur.x + Dx[cur.type - 2], cur.y + Dy[cur.type - 2], cur.type, cur.dist + A);
}
}
}
}
Compilation message
soccer.cpp: In function 'int main()':
soccer.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
66 | scanf("%d %d\n%lld %lld %lld\n%d",&H,&W,&A,&B,&C,&N);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
68 | scanf("%d %d",&P[i][0], &P[i][1]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
11876 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
162 ms |
39016 KB |
Output is correct |
4 |
Correct |
79 ms |
26720 KB |
Output is correct |
5 |
Correct |
47 ms |
7552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
26584 KB |
Output is correct |
2 |
Correct |
51 ms |
20464 KB |
Output is correct |
3 |
Correct |
216 ms |
36168 KB |
Output is correct |
4 |
Correct |
534 ms |
38984 KB |
Output is correct |
5 |
Correct |
271 ms |
38476 KB |
Output is correct |
6 |
Correct |
326 ms |
38984 KB |
Output is correct |
7 |
Correct |
169 ms |
38956 KB |
Output is correct |
8 |
Correct |
204 ms |
38984 KB |
Output is correct |
9 |
Correct |
37 ms |
17484 KB |
Output is correct |
10 |
Correct |
32 ms |
9460 KB |
Output is correct |
11 |
Correct |
318 ms |
38968 KB |
Output is correct |
12 |
Correct |
320 ms |
39000 KB |
Output is correct |
13 |
Correct |
250 ms |
36168 KB |
Output is correct |
14 |
Correct |
152 ms |
38968 KB |
Output is correct |
15 |
Correct |
30 ms |
17004 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
44 ms |
11876 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
162 ms |
39016 KB |
Output is correct |
4 |
Correct |
79 ms |
26720 KB |
Output is correct |
5 |
Correct |
47 ms |
7552 KB |
Output is correct |
6 |
Correct |
74 ms |
26584 KB |
Output is correct |
7 |
Correct |
51 ms |
20464 KB |
Output is correct |
8 |
Correct |
216 ms |
36168 KB |
Output is correct |
9 |
Correct |
534 ms |
38984 KB |
Output is correct |
10 |
Correct |
271 ms |
38476 KB |
Output is correct |
11 |
Correct |
326 ms |
38984 KB |
Output is correct |
12 |
Correct |
169 ms |
38956 KB |
Output is correct |
13 |
Correct |
204 ms |
38984 KB |
Output is correct |
14 |
Correct |
37 ms |
17484 KB |
Output is correct |
15 |
Correct |
32 ms |
9460 KB |
Output is correct |
16 |
Correct |
318 ms |
38968 KB |
Output is correct |
17 |
Correct |
320 ms |
39000 KB |
Output is correct |
18 |
Correct |
250 ms |
36168 KB |
Output is correct |
19 |
Correct |
152 ms |
38968 KB |
Output is correct |
20 |
Correct |
30 ms |
17004 KB |
Output is correct |
21 |
Correct |
27 ms |
7480 KB |
Output is correct |
22 |
Correct |
557 ms |
38984 KB |
Output is correct |
23 |
Correct |
669 ms |
25304 KB |
Output is correct |
24 |
Correct |
406 ms |
26644 KB |
Output is correct |
25 |
Correct |
470 ms |
38984 KB |
Output is correct |
26 |
Correct |
554 ms |
39164 KB |
Output is correct |
27 |
Correct |
164 ms |
15508 KB |
Output is correct |
28 |
Correct |
280 ms |
16040 KB |
Output is correct |
29 |
Correct |
612 ms |
28428 KB |
Output is correct |
30 |
Correct |
215 ms |
17392 KB |
Output is correct |
31 |
Correct |
115 ms |
26684 KB |
Output is correct |
32 |
Correct |
241 ms |
40564 KB |
Output is correct |
33 |
Correct |
379 ms |
38984 KB |
Output is correct |
34 |
Correct |
59 ms |
20544 KB |
Output is correct |
35 |
Correct |
199 ms |
15876 KB |
Output is correct |