#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define endl "\n"
#define fr first
#define sc second
#define sz size()
#define ins insert
#define bc back()
#define str string
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e18+7;
const ll mod=1e9;
const ll N=5e2+7;
const ld eps=1e-9;
struct node{
ll x,y,tp,d;
bool operator <(const node &b)const{
return d>b.d;
}
};
ll d[N][N][5];
priority_queue<node> pq;
ll xd[4]={-1,1,0,0},yd[4]={0,0,-1,1};
ll l,w,n,a,b,c,x,y;
bool ok(ll x,ll y){
return x<=l && x>=0 && y<=w && y>=0;
}
void inq(ll x,ll y,ll tp,ll dd){
if(!ok(x,y))return;
if(d[x][y][tp]>dd){
d[x][y][tp]=dd;
pq.push({x,y,tp,dd});
}
}
void solve(){
ll i,j;
cin>>l>>w>>a>>b>>c>>n;
ll dis[l+1][w+1];
queue<pair<ll,ll>> q;
vector<pair<ll,ll>> v;
memset(dis,0x3f,sizeof(dis));
for(i=0;i<n;i++){
cin>>x>>y;
v.pb({x,y});
dis[x][y]=0;
q.push({x,y});
}
while(q.sz){
ll x=q.front().fr,y=q.front().sc;
q.pop();
for(i=0;i<4;i++){
if(!ok(x+xd[i],y+yd[i])) continue;
if(dis[x+xd[i]][y+yd[i]]>dis[x][y]+1){
dis[x+xd[i]][y+yd[i]]=dis[x][y]+1;
q.push({x+xd[i],y+yd[i]});
}
}
}
memset(d,0x3f,sizeof(d));
pq.push({v[0].fr,v[0].sc,4,0});
d[v[0].fr][v[0].sc][4]=0;
b+=a;
while(pq.sz){
node x=pq.top();
pq.pop();
if(x.d!=d[x.x][x.y][x.tp])continue;
if(x.tp==4){
for(i=0;i<4;i++){
inq(x.x+xd[i],x.y+yd[i],4ll,x.d+c);
inq(x.x+xd[i],x.y+yd[i],i,x.d+b);
}
}else{
inq(x.x+xd[x.tp],x.y+yd[x.tp],x.tp,x.d+a);
inq(x.x,x.y,4ll,x.d+c*dis[x.x][x.y]);
}
}
cout<<d[v.bc.fr][v.bc.sc][4]<<endl;
}
signed main(){
start();
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
*/
Compilation message
soccer.cpp: In function 'void solve()':
soccer.cpp:50:7: warning: unused variable 'j' [-Wunused-variable]
50 | ll i,j;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
13012 KB |
Output is correct |
2 |
Correct |
2 ms |
10328 KB |
Output is correct |
3 |
Correct |
205 ms |
22336 KB |
Output is correct |
4 |
Correct |
207 ms |
21688 KB |
Output is correct |
5 |
Correct |
34 ms |
11356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
222 ms |
21696 KB |
Output is correct |
2 |
Correct |
215 ms |
21948 KB |
Output is correct |
3 |
Correct |
161 ms |
21180 KB |
Output is correct |
4 |
Correct |
166 ms |
21756 KB |
Output is correct |
5 |
Correct |
172 ms |
22204 KB |
Output is correct |
6 |
Correct |
180 ms |
22124 KB |
Output is correct |
7 |
Correct |
198 ms |
21440 KB |
Output is correct |
8 |
Correct |
205 ms |
22764 KB |
Output is correct |
9 |
Correct |
223 ms |
22712 KB |
Output is correct |
10 |
Correct |
31 ms |
13008 KB |
Output is correct |
11 |
Correct |
200 ms |
21288 KB |
Output is correct |
12 |
Correct |
204 ms |
22712 KB |
Output is correct |
13 |
Correct |
140 ms |
22200 KB |
Output is correct |
14 |
Correct |
211 ms |
21924 KB |
Output is correct |
15 |
Correct |
150 ms |
20828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
48 ms |
13012 KB |
Output is correct |
2 |
Correct |
2 ms |
10328 KB |
Output is correct |
3 |
Correct |
205 ms |
22336 KB |
Output is correct |
4 |
Correct |
207 ms |
21688 KB |
Output is correct |
5 |
Correct |
34 ms |
11356 KB |
Output is correct |
6 |
Correct |
222 ms |
21696 KB |
Output is correct |
7 |
Correct |
215 ms |
21948 KB |
Output is correct |
8 |
Correct |
161 ms |
21180 KB |
Output is correct |
9 |
Correct |
166 ms |
21756 KB |
Output is correct |
10 |
Correct |
172 ms |
22204 KB |
Output is correct |
11 |
Correct |
180 ms |
22124 KB |
Output is correct |
12 |
Correct |
198 ms |
21440 KB |
Output is correct |
13 |
Correct |
205 ms |
22764 KB |
Output is correct |
14 |
Correct |
223 ms |
22712 KB |
Output is correct |
15 |
Correct |
31 ms |
13008 KB |
Output is correct |
16 |
Correct |
200 ms |
21288 KB |
Output is correct |
17 |
Correct |
204 ms |
22712 KB |
Output is correct |
18 |
Correct |
140 ms |
22200 KB |
Output is correct |
19 |
Correct |
211 ms |
21924 KB |
Output is correct |
20 |
Correct |
150 ms |
20828 KB |
Output is correct |
21 |
Correct |
45 ms |
12424 KB |
Output is correct |
22 |
Correct |
268 ms |
21392 KB |
Output is correct |
23 |
Correct |
238 ms |
16868 KB |
Output is correct |
24 |
Correct |
276 ms |
17180 KB |
Output is correct |
25 |
Correct |
236 ms |
22872 KB |
Output is correct |
26 |
Correct |
249 ms |
22228 KB |
Output is correct |
27 |
Correct |
103 ms |
16200 KB |
Output is correct |
28 |
Correct |
127 ms |
17068 KB |
Output is correct |
29 |
Correct |
235 ms |
23216 KB |
Output is correct |
30 |
Correct |
112 ms |
16448 KB |
Output is correct |
31 |
Correct |
208 ms |
21172 KB |
Output is correct |
32 |
Correct |
252 ms |
26436 KB |
Output is correct |
33 |
Correct |
200 ms |
21440 KB |
Output is correct |
34 |
Correct |
245 ms |
21436 KB |
Output is correct |
35 |
Correct |
106 ms |
16464 KB |
Output is correct |