#include<bits/stdc++.h>
#define LL long long
using namespace std;
LL A,B,C;
int Head[8000005],Cnt,N,M,D[505][505],Mantot,Arrive[505][505];
struct Point{int Xh,Yh;}P[8000005];
struct Edge{int Next,To; LL W;}E[8000005];
void Add_Edge(int X1,int Y1,LL Z1){E[++Cnt].Next=Head[X1],E[Cnt].To=Y1,E[Cnt].W=Z1,Head[X1]=Cnt;}
int Change(int X0,int Y0,int K0){return K0*(N+1)*(M+1)+X0*(M+1)+Y0;}
const int Go[4][2]={{1,0},{-1,0},{0,1},{0,-1}};
void BFS(){
queue<pair<int,int> >Que;
memset(D,0x3f,sizeof(D));
for(int I=1;I<=Mantot;I++) Que.push(make_pair(P[I].Xh,P[I].Yh)),D[P[I].Xh][P[I].Yh]=0;
while(!Que.empty()){
pair<int,int> Par=Que.front(); Que.pop();
Arrive[Par.first][Par.second]=0;
for(int I=0;I<4;I++){
int Nx=Par.first+Go[I][0],Ny=Par.second+Go[I][1];
if(Nx>N||Nx<0||Ny>M||Ny<0) continue;
if(D[Nx][Ny]>D[Par.first][Par.second]+1){
D[Nx][Ny]=D[Par.first][Par.second]+1;
if(!Arrive[Nx][Ny]) Que.push(make_pair(Nx,Ny)),Arrive[Nx][Ny]=1;
}
}
}
}
struct Node{
int Id;
LL Dis;
bool operator < (const Node& B)const{
return Dis>B.Dis;
}
};
int Vis[8000005];
LL Best[8000005];
void Dijkstra(){
priority_queue<Node>Q;
memset(Best,0x3f,sizeof(Best));
memset(Vis,0,sizeof(Vis));
Q.push((Node){Change(P[1].Xh,P[1].Yh,4),0}),Best[Change(P[1].Xh,P[1].Yh,4)]=0;
while(!Q.empty()){
Node Tp=Q.top(); Q.pop();
if(Vis[Tp.Id]) continue;
Vis[Tp.Id]=1;
for(int I=Head[Tp.Id];I;I=E[I].Next){
int Y=E[I].To;
if(Best[Y]<=Best[Tp.Id]+E[I].W) continue;
Best[Y]=Best[Tp.Id]+E[I].W,Q.push((Node){Y,Best[Y]});
}
}
}
signed main(){
scanf("%d%d%lld%lld%lld%d",&N,&M,&A,&B,&C,&Mantot);
for(int I=1;I<=Mantot;I++) scanf("%d%d",&P[I].Xh,&P[I].Yh);
BFS();
for(int I=0;I<=N;I++)
for(int J=0;J<=M;J++)
for(int U=0;U<4;U++){
Add_Edge(Change(I,J,U),Change(I,J,4),0LL);
Add_Edge(Change(I,J,4),Change(I,J,5),1LL*C*D[I][J]);
Add_Edge(Change(I,J,5),Change(I,J,U),1LL*B);
int Nx=I+Go[U][0],Ny=J+Go[U][1];
if(Nx<0||Ny<0||Nx>N||Ny>M) continue;
Add_Edge(Change(I,J,U),Change(Nx,Ny,U),1LL*A);
Add_Edge(Change(I,J,5),Change(Nx,Ny,5),1LL*C);
}
Dijkstra();
LL Ans=0x3f3f3f3f3f3f3f3f;
for(int I=0;I<6;I++) Ans=min(Ans,Best[Change(P[Mantot].Xh,P[Mantot].Yh,I)]);
printf("%lld",Ans);
return 0;
}
Compilation message
soccer.cpp: In function 'int main()':
soccer.cpp:54:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
54 | scanf("%d%d%lld%lld%lld%d",&N,&M,&A,&B,&C,&Mantot);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:55:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
55 | for(int I=1;I<=Mantot;I++) scanf("%d%d",&P[I].Xh,&P[I].Yh);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
117348 KB |
Output is correct |
2 |
Correct |
52 ms |
95340 KB |
Output is correct |
3 |
Correct |
675 ms |
184924 KB |
Output is correct |
4 |
Correct |
710 ms |
184924 KB |
Output is correct |
5 |
Correct |
148 ms |
126956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
814 ms |
185084 KB |
Output is correct |
2 |
Correct |
820 ms |
184924 KB |
Output is correct |
3 |
Correct |
557 ms |
167900 KB |
Output is correct |
4 |
Correct |
557 ms |
185088 KB |
Output is correct |
5 |
Correct |
578 ms |
168156 KB |
Output is correct |
6 |
Correct |
574 ms |
185052 KB |
Output is correct |
7 |
Correct |
785 ms |
185120 KB |
Output is correct |
8 |
Correct |
686 ms |
185052 KB |
Output is correct |
9 |
Correct |
771 ms |
185120 KB |
Output is correct |
10 |
Correct |
150 ms |
111076 KB |
Output is correct |
11 |
Correct |
782 ms |
185136 KB |
Output is correct |
12 |
Correct |
787 ms |
185084 KB |
Output is correct |
13 |
Correct |
427 ms |
168028 KB |
Output is correct |
14 |
Correct |
772 ms |
185120 KB |
Output is correct |
15 |
Correct |
623 ms |
168156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
117348 KB |
Output is correct |
2 |
Correct |
52 ms |
95340 KB |
Output is correct |
3 |
Correct |
675 ms |
184924 KB |
Output is correct |
4 |
Correct |
710 ms |
184924 KB |
Output is correct |
5 |
Correct |
148 ms |
126956 KB |
Output is correct |
6 |
Correct |
814 ms |
185084 KB |
Output is correct |
7 |
Correct |
820 ms |
184924 KB |
Output is correct |
8 |
Correct |
557 ms |
167900 KB |
Output is correct |
9 |
Correct |
557 ms |
185088 KB |
Output is correct |
10 |
Correct |
578 ms |
168156 KB |
Output is correct |
11 |
Correct |
574 ms |
185052 KB |
Output is correct |
12 |
Correct |
785 ms |
185120 KB |
Output is correct |
13 |
Correct |
686 ms |
185052 KB |
Output is correct |
14 |
Correct |
771 ms |
185120 KB |
Output is correct |
15 |
Correct |
150 ms |
111076 KB |
Output is correct |
16 |
Correct |
782 ms |
185136 KB |
Output is correct |
17 |
Correct |
787 ms |
185084 KB |
Output is correct |
18 |
Correct |
427 ms |
168028 KB |
Output is correct |
19 |
Correct |
772 ms |
185120 KB |
Output is correct |
20 |
Correct |
623 ms |
168156 KB |
Output is correct |
21 |
Correct |
170 ms |
126700 KB |
Output is correct |
22 |
Correct |
925 ms |
184968 KB |
Output is correct |
23 |
Correct |
887 ms |
174432 KB |
Output is correct |
24 |
Correct |
949 ms |
183188 KB |
Output is correct |
25 |
Correct |
750 ms |
184960 KB |
Output is correct |
26 |
Correct |
815 ms |
185180 KB |
Output is correct |
27 |
Correct |
441 ms |
182708 KB |
Output is correct |
28 |
Correct |
447 ms |
183392 KB |
Output is correct |
29 |
Correct |
712 ms |
184988 KB |
Output is correct |
30 |
Correct |
405 ms |
182872 KB |
Output is correct |
31 |
Correct |
814 ms |
185052 KB |
Output is correct |
32 |
Correct |
984 ms |
187236 KB |
Output is correct |
33 |
Correct |
656 ms |
185024 KB |
Output is correct |
34 |
Correct |
968 ms |
185248 KB |
Output is correct |
35 |
Correct |
426 ms |
183276 KB |
Output is correct |