#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define inf 1000000000000000007
#define ek(a,b,c,d,e) mp(a,mp(mp(b,c),mp(d,e)))
#define N 505
using namespace std;
typedef long long ll;
typedef pair < ll , ll > ii;
typedef pair < ii , ii > i4;
ll n, m, k, x[100005], y[100005];
ll a, b, c, ans = inf, d[N][N][4][4];
ll o[] = {0, 0, 1, -1};
ll p[] = {1, -1, 0, 0};
priority_queue < pair < ll , i4 > > q;
bool git(ll i, ll j){return !(i < 1 or j < 1 or i > n or j > m);}
int main() {
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
memset(d, 60, sizeof d);
scanf("%lld %lld %lld %lld %lld %lld",&n ,&m ,&a ,&b ,&c ,&k);n++;m++;
scanf("%lld %lld",x + 1, y + 1);x[1]++;y[1]++;
d[x[1]][y[1]][3][0] = 0;
q.push(ek(0, x[1], y[1], 3, 0));
for(ll i = 2; i <= k; i++){
scanf("%lld %lld",x + i, y + i);x[i]++;y[i]++;
d[x[i]][y[i]][2][0] = 0;
q.push(ek(0, x[i], y[i], 2, 0));
}
while(!q.empty()){
pair < ll , i4 > tp = q.top();q.pop();
ll x = tp.nd.st.st, y = tp.nd.st.nd, dur = tp.nd.nd.st, yon = tp.nd.nd.nd;
if(dur == 0){
if(d[x][y][1][0] > d[x][y][0][yon]){//Topu durdur.
d[x][y][1][0] = d[x][y][0][yon];
q.push(ek(-d[x][y][1][0], x, y, 1, 0));
}
if(git(x + o[yon], y + p[yon]) and d[x + o[yon]][y + p[yon]][0][yon] > d[x][y][0][yon] + a){
d[x + o[yon]][y + p[yon]][0][yon] = d[x][y][0][yon] + a;
q.push(ek(-d[x + o[yon]][y + p[yon]][0][yon], x + o[yon], y + p[yon], 0, yon));
}
}
if(dur == 1){
if(d[x][y][3][0] > d[x][y][1][0] + d[x][y][2][0]){
d[x][y][3][0] = d[x][y][1][0] + d[x][y][2][0];
q.push(ek(-d[x][y][3][0], x, y, 3, 0));
}
}
if(dur == 2){
if(d[x][y][3][0] > d[x][y][1][0] + d[x][y][2][0]){
d[x][y][3][0] = d[x][y][1][0] + d[x][y][2][0];
q.push(ek(-d[x][y][3][0], x, y, 3, 0));
}
for(ll i = 0; i < 4; i++){
if(git(x + o[i], y + p[i]) and d[x + o[i]][y + p[i]][2][0] > d[x][y][2][0] + c){
d[x + o[i]][y + p[i]][2][0] = d[x][y][2][0] + c;
q.push(ek(-d[x + o[yon]][y + p[yon]][2][0], x + o[yon], y + p[yon], 2, 0));
}
}
}
if(dur == 3){
for(ll i = 0; i < 4; i++){
if(git(x + o[i], y + p[i]) and d[x + o[i]][y + p[i]][3][0] > d[x][y][3][0] + c){
d[x + o[i]][y + p[i]][3][0] = d[x][y][3][0] + c;
q.push(ek(-d[x + o[yon]][y + p[yon]][3][0], x + o[yon], y + p[yon], 3, 0));
}
}
for(ll i = 0; i < 4; i++){
if(d[x][y][0][i] > d[x][y][3][0] + b){
d[x][y][0][i] = d[x][y][3][0] + b;
q.push(ek(-d[x][y][0][i], x, y, 0, i));
}
}
if(d[x][y][1][0] > d[x][y][3][0]){
d[x][y][1][0] = d[x][y][3][0];
q.push(ek(-d[x][y][1][0], x, y, 1, 0));
}
if(d[x][y][2][0] > d[x][y][3][0]){
d[x][y][2][0] = d[x][y][3][0];
q.push(ek(-d[x][y][2][0], x, y, 2, 0));
}
}
}
for(ll i = 1; i <= n; i++)
for(ll j = 1; j <= m; j++)
ans = min(ans, abs(x[k] - i)*c + abs(y[k] - j)*c + d[i][j][1][0]);
printf("%lld\n", ans);
return 0;
}
Compilation message
soccer.cpp: In function 'int main()':
soccer.cpp:27: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",&n ,&m ,&a ,&b ,&c ,&k);n++;m++;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",x + 1, y + 1);x[1]++;y[1]++;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:32:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld",x + i, y + i);x[i]++;y[i]++;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
32248 KB |
Output is correct |
2 |
Correct |
36 ms |
32400 KB |
Output is correct |
3 |
Correct |
79 ms |
32400 KB |
Output is correct |
4 |
Correct |
96 ms |
32400 KB |
Output is correct |
5 |
Correct |
54 ms |
32400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
292 ms |
32868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
69 ms |
32248 KB |
Output is correct |
2 |
Correct |
36 ms |
32400 KB |
Output is correct |
3 |
Correct |
79 ms |
32400 KB |
Output is correct |
4 |
Correct |
96 ms |
32400 KB |
Output is correct |
5 |
Correct |
54 ms |
32400 KB |
Output is correct |
6 |
Incorrect |
292 ms |
32868 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |