This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define lo long long
#define inf 1000000000000000000
#define md 1000000007
#define pb push_back
#define li 100005
#define ii pair<lo int,lo int>
#define iii pair<lo int ,ii>
using namespace std;
typedef array<lo int,4> T;
lo int h,w,A,B,C,n,s[li],t[li],dist[505][505],dx[5]={0,-1,1,0},dy[5]={1,0,0,-1};
queue< iii > qq;
lo int dp[505][505][6];
priority_queue<T,vector<T>,greater<T>> q;
void tri(int p0,int p1,int z,lo int res){
if(p0<0 || p1<0 || p0>h || p1>w) return ;
if(dp[p0][p1][z]<=res) return ;
q.push({dp[p0][p1][z]=res,p0,p1,z});
}
void bfs(){
q.push({dp[s[1]][s[2]][4]=0,s[1],t[1],4});
while(!q.empty()){
auto a=q.top();
q.pop();
if(a[0]>dp[a[1]][a[2]][a[3]]) continue;
if(a[3]<4){
tri(a[1]+dx[a[3]],a[2]+dy[a[3]],a[3],a[0]+A);
tri(a[1],a[2],4,dp[a[1]][a[2]][a[3]]);
}
else if(a[3]==4){
tri(a[1],a[2],5,a[0]+C*dist[a[1]][a[2]]);
}
else{
for(int i=0;i<=3;i++){
tri(a[1],a[2],i,a[0]+B);
tri(a[1]+dx[i],a[2]+dy[i],5,a[0]+C);
}
tri(a[1],a[2],4,a[0]);
}
}
printf("%lld\n",dp[s[n]][t[n]][4]);
}
int main(){
scanf("%lld %lld %lld %lld %lld %lld",&h,&w,&A,&B,&C,&n);
for(int i=0;i<=h;i++){
for(int j=0;j<=w;j++){
dist[i][j]=inf;
for(int k=0;k<=5;k++) dp[i][j][k]=inf;
}
}
for(int i=1;i<=n;i++){
scanf("%lld %lld",&s[i],&t[i]);
qq.push(mp(0,mp(s[i],t[i])));
dist[s[i]][t[i]]=0;
}
while(!qq.empty()){
iii temp=qq.front();
qq.pop();
ii seh=temp.se;
lo int cst=temp.fi;
dist[seh.fi][seh.se]=cst;
for(int i=0;i<=3;i++){
lo int gox=dx[i]+seh.fi;
lo int goy=dy[i]+seh.se;
if(gox<0 || goy<0 || gox>h || goy>w || dist[gox][goy]!=inf) continue;
dist[gox][goy]=cst+1;
qq.push(mp(cst+1,mp(gox,goy)));
}
}
//~ for(int i=0;i<=h;i++){
//~ for(int j=0;j<=w;j++){
//~ printf("%lld ",dist[i][j]);
//~ }
//~ printf("\n");
//~ }
bfs();
return 0;
}
Compilation message (stderr)
soccer.cpp: In function 'int main()':
soccer.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld %lld %lld %lld",&h,&w,&A,&B,&C,&n);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",&s[i],&t[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |