#include <bits/stdc++.h>
typedef long long lint;
typedef long double llf;
using namespace std;
typedef pair<int, int> pi;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int n, m;
lint a, b, c;
int dis[505][505];
bool ok(int x, int y){
return x >= 0 && x <= n && y >= 0 && y <= m;
}
struct node{
int x, y, typ;
lint dis;
bool operator<(const node &c)const{
return dis > c.dis;
}
};
priority_queue<node> pq;
lint dist[505][505][5];
void enqueue(int x, int y, int t, lint d){
if(!ok(x, y)) return;
if(dist[x][y][t] > d){
dist[x][y][t] = d;
pq.push({x, y, t, d});
}
}
int main(){
memset(dis, 0x3f, sizeof(dis));
int t;
cin >> n >> m >> a >> b >> c >> t;
if(n>1000) return 0;
queue<pi> que;
pi st, ed;
for(int i=0; i<t; i++){
int x, y;
scanf("%d %d",&x,&y);
if(i == 0) st = pi(x, y);
if(i == t-1) ed = pi(x, y);
dis[x][y] = 0;
que.push(pi(x, y));
}
while(!que.empty()){
auto x = que.front();
que.pop();
for(int i=0; i<4; i++){
if(ok(x.first + dx[i], x.second + dy[i]) && dis[x.first + dx[i]][x.second + dy[i]] > 1e9){
dis[x.first + dx[i]][x.second + dy[i]] = dis[x.first][x.second] + 1;
que.push(pi(x.first + dx[i], x.second + dy[i]));
}
}
}
memset(dist, 0x3f, sizeof(dist));
enqueue(st.first, st.second, 4, 0);
while(!pq.empty()){
auto x = pq.top();
pq.pop();
if(dist[x.x][x.y][x.typ] != x.dis) continue;
if(x.typ == 4){
for(int i=0; i<4; i++){
enqueue(x.x + dx[i], x.y + dy[i], 4, x.dis + c);
enqueue(x.x, x.y, i, x.dis + b);
}
}
else{
enqueue(x.x + dx[x.typ], x.y + dy[x.typ], x.typ, x.dis + a);
enqueue(x.x, x.y, 4, x.dis + dis[x.x][x.y] * c);
}
}
cout << dist[ed.first][ed.second][4];
}
Compilation message
soccer.cpp: In function 'int main()':
soccer.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&x,&y);
~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
13028 KB |
Output is correct |
2 |
Correct |
14 ms |
13028 KB |
Output is correct |
3 |
Correct |
504 ms |
17764 KB |
Output is correct |
4 |
Correct |
594 ms |
17764 KB |
Output is correct |
5 |
Correct |
105 ms |
17764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
677 ms |
17780 KB |
Output is correct |
2 |
Correct |
702 ms |
17888 KB |
Output is correct |
3 |
Correct |
413 ms |
17960 KB |
Output is correct |
4 |
Correct |
386 ms |
17960 KB |
Output is correct |
5 |
Correct |
432 ms |
17960 KB |
Output is correct |
6 |
Correct |
477 ms |
17960 KB |
Output is correct |
7 |
Correct |
536 ms |
18028 KB |
Output is correct |
8 |
Correct |
477 ms |
18028 KB |
Output is correct |
9 |
Correct |
614 ms |
18028 KB |
Output is correct |
10 |
Correct |
94 ms |
18028 KB |
Output is correct |
11 |
Correct |
674 ms |
18100 KB |
Output is correct |
12 |
Correct |
608 ms |
18100 KB |
Output is correct |
13 |
Correct |
348 ms |
18100 KB |
Output is correct |
14 |
Correct |
686 ms |
18100 KB |
Output is correct |
15 |
Correct |
478 ms |
18100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
13028 KB |
Output is correct |
2 |
Correct |
14 ms |
13028 KB |
Output is correct |
3 |
Correct |
504 ms |
17764 KB |
Output is correct |
4 |
Correct |
594 ms |
17764 KB |
Output is correct |
5 |
Correct |
105 ms |
17764 KB |
Output is correct |
6 |
Correct |
677 ms |
17780 KB |
Output is correct |
7 |
Correct |
702 ms |
17888 KB |
Output is correct |
8 |
Correct |
413 ms |
17960 KB |
Output is correct |
9 |
Correct |
386 ms |
17960 KB |
Output is correct |
10 |
Correct |
432 ms |
17960 KB |
Output is correct |
11 |
Correct |
477 ms |
17960 KB |
Output is correct |
12 |
Correct |
536 ms |
18028 KB |
Output is correct |
13 |
Correct |
477 ms |
18028 KB |
Output is correct |
14 |
Correct |
614 ms |
18028 KB |
Output is correct |
15 |
Correct |
94 ms |
18028 KB |
Output is correct |
16 |
Correct |
674 ms |
18100 KB |
Output is correct |
17 |
Correct |
608 ms |
18100 KB |
Output is correct |
18 |
Correct |
348 ms |
18100 KB |
Output is correct |
19 |
Correct |
686 ms |
18100 KB |
Output is correct |
20 |
Correct |
478 ms |
18100 KB |
Output is correct |
21 |
Correct |
116 ms |
18100 KB |
Output is correct |
22 |
Correct |
709 ms |
18160 KB |
Output is correct |
23 |
Correct |
666 ms |
18160 KB |
Output is correct |
24 |
Correct |
626 ms |
18160 KB |
Output is correct |
25 |
Correct |
538 ms |
18160 KB |
Output is correct |
26 |
Correct |
687 ms |
18280 KB |
Output is correct |
27 |
Correct |
371 ms |
18280 KB |
Output is correct |
28 |
Correct |
319 ms |
18280 KB |
Output is correct |
29 |
Correct |
592 ms |
18280 KB |
Output is correct |
30 |
Correct |
279 ms |
18280 KB |
Output is correct |
31 |
Correct |
564 ms |
18548 KB |
Output is correct |
32 |
Correct |
660 ms |
19188 KB |
Output is correct |
33 |
Correct |
486 ms |
19188 KB |
Output is correct |
34 |
Correct |
689 ms |
19188 KB |
Output is correct |
35 |
Correct |
260 ms |
19188 KB |
Output is correct |