#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
const int MAXH = 500;
const ll INF = 1e18;
struct Point { int y, x; };
const int dy[]={-1, 1, 0, 0};
const int dx[]={0, 0, -1, 1};
int H, W, N;
ll A, B, C, ans;
Point S[MAXN+10];
struct Queue
{
int y, x, t; ll w;
bool operator < (const Queue &p) const { return w>p.w; }
};
ll close[MAXH+10][MAXH+10];
ll dist[MAXH+10][MAXH+10][5];
int main()
{
int i, j, k;
scanf("%d%d%lld%lld%lld%d", &H, &W, &A, &B, &C, &N);
for(i=1; i<=N; i++) scanf("%d%d", &S[i].y, &S[i].x);
for(i=0; i<=H; i++) for(j=0; j<=W; j++) close[i][j]=INF;
priority_queue<Queue> PQ;
for(i=1; i<=N; i++) PQ.push({S[i].y, S[i].x, -1, 0});
while(!PQ.empty())
{
Queue T=PQ.top(); PQ.pop();
if(close[T.y][T.x]<=T.w) continue;
close[T.y][T.x]=T.w;
for(i=0; i<4; i++)
{
int ny=T.y+dy[i], nx=T.x+dx[i];
if(0<=ny && ny<=H && 0<=nx && nx<=W) PQ.push({ny, nx, -1, T.w+C});
}
}
for(i=0; i<=H; i++) for(j=0; j<=W; j++) for(k=0; k<5; k++) dist[i][j][k]=INF;
PQ.push({S[1].y, S[1].x, 4, 0});
while(!PQ.empty())
{
Queue T=PQ.top(); PQ.pop();
if(dist[T.y][T.x][T.t]<=T.w) continue;
dist[T.y][T.x][T.t]=T.w;
if(T.t<4)
{
PQ.push({T.y, T.x, 4, T.w});
int ny=T.y+dy[T.t], nx=T.x+dx[T.t];
if(0<=ny && ny<=H && 0<=nx && nx<=W) PQ.push({ny, nx, T.t, T.w+A});
}
else
{
for(i=0; i<4; i++) PQ.push({T.y, T.x, i, T.w+close[T.y][T.x]+B});
for(i=0; i<4; i++)
{
int ny=T.y+dy[i], nx=T.x+dx[i];
if(0<=ny && ny<=H && 0<=nx && nx<=W) PQ.push({ny, nx, 4, T.w+C});
}
}
}
printf("%lld", min({dist[S[N].y][S[N].x][0], dist[S[N].y][S[N].x][1], dist[S[N].y][S[N].x][2], dist[S[N].y][S[N].x][3], dist[S[N].y][S[N].x][4]}));
}
Compilation message
soccer.cpp: In function 'int main()':
soccer.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%lld%lld%lld%d", &H, &W, &A, &B, &C, &N);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:34:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(i=1; i<=N; i++) scanf("%d%d", &S[i].y, &S[i].x);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
11516 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1045 ms |
37188 KB |
Output is correct |
4 |
Correct |
1034 ms |
37108 KB |
Output is correct |
5 |
Correct |
292 ms |
13156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1035 ms |
37120 KB |
Output is correct |
2 |
Correct |
984 ms |
37192 KB |
Output is correct |
3 |
Correct |
747 ms |
34812 KB |
Output is correct |
4 |
Correct |
936 ms |
37356 KB |
Output is correct |
5 |
Correct |
770 ms |
37008 KB |
Output is correct |
6 |
Correct |
961 ms |
37232 KB |
Output is correct |
7 |
Correct |
1059 ms |
61740 KB |
Output is correct |
8 |
Correct |
1046 ms |
61744 KB |
Output is correct |
9 |
Correct |
998 ms |
61732 KB |
Output is correct |
10 |
Correct |
131 ms |
12256 KB |
Output is correct |
11 |
Correct |
1101 ms |
61744 KB |
Output is correct |
12 |
Correct |
962 ms |
37224 KB |
Output is correct |
13 |
Correct |
722 ms |
34696 KB |
Output is correct |
14 |
Correct |
1038 ms |
61868 KB |
Output is correct |
15 |
Correct |
810 ms |
61640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
226 ms |
11516 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
1045 ms |
37188 KB |
Output is correct |
4 |
Correct |
1034 ms |
37108 KB |
Output is correct |
5 |
Correct |
292 ms |
13156 KB |
Output is correct |
6 |
Correct |
1035 ms |
37120 KB |
Output is correct |
7 |
Correct |
984 ms |
37192 KB |
Output is correct |
8 |
Correct |
747 ms |
34812 KB |
Output is correct |
9 |
Correct |
936 ms |
37356 KB |
Output is correct |
10 |
Correct |
770 ms |
37008 KB |
Output is correct |
11 |
Correct |
961 ms |
37232 KB |
Output is correct |
12 |
Correct |
1059 ms |
61740 KB |
Output is correct |
13 |
Correct |
1046 ms |
61744 KB |
Output is correct |
14 |
Correct |
998 ms |
61732 KB |
Output is correct |
15 |
Correct |
131 ms |
12256 KB |
Output is correct |
16 |
Correct |
1101 ms |
61744 KB |
Output is correct |
17 |
Correct |
962 ms |
37224 KB |
Output is correct |
18 |
Correct |
722 ms |
34696 KB |
Output is correct |
19 |
Correct |
1038 ms |
61868 KB |
Output is correct |
20 |
Correct |
810 ms |
61640 KB |
Output is correct |
21 |
Correct |
259 ms |
9468 KB |
Output is correct |
22 |
Correct |
1214 ms |
37040 KB |
Output is correct |
23 |
Correct |
1099 ms |
23640 KB |
Output is correct |
24 |
Correct |
1206 ms |
24772 KB |
Output is correct |
25 |
Correct |
1125 ms |
37120 KB |
Output is correct |
26 |
Correct |
1097 ms |
37212 KB |
Output is correct |
27 |
Correct |
688 ms |
25460 KB |
Output is correct |
28 |
Correct |
742 ms |
28604 KB |
Output is correct |
29 |
Correct |
987 ms |
26468 KB |
Output is correct |
30 |
Correct |
824 ms |
21320 KB |
Output is correct |
31 |
Correct |
1165 ms |
61728 KB |
Output is correct |
32 |
Correct |
1268 ms |
38648 KB |
Output is correct |
33 |
Correct |
975 ms |
37172 KB |
Output is correct |
34 |
Correct |
1250 ms |
37076 KB |
Output is correct |
35 |
Correct |
697 ms |
17308 KB |
Output is correct |