#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define FOR(i, l, r, d) for(int i=(l); i<=(r); i+=(d))
#define szof(x) ((int)(x).size())
#define vi vector<int>
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define mkp make_pair
const int INF = 2147483647;
const int LNF = INF*INF;
const int MOD = 1000000007;
const int mod = 998244353;
const double eps = 1e-12;
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
const int MAX = 100010;
int h, w;
int a, b, c;
int n;
pii pt[MAX];
vector<pii> edge[MAX];
int dis[MAX];
void Dijkstra(){
dis[1] = 0;
FOR(i, 2, n, 1){
dis[i] = LNF;
}
priority_queue<pii, vector<pii>, greater<pii>> pq;
pq.emplace(0, 1);
while(!pq.empty()){
int v = pq.top().S;
int disv = pq.top().F;
pq.pop();
if(disv > dis[v]) continue;
for(pii e : edge[v]){
int u = e.F, duv = e.S;
if(dis[v] + duv < dis[u]){
dis[u] = dis[v] + duv;
pq.emplace(dis[u], u);
}
}
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>h>>w;
cin>>a>>b>>c;
cin>>n;
FOR(i, 1, n, 1){
cin>>pt[i].F>>pt[i].S;
}
FOR(i, 1, n, 1){
FOR(j, 1, i-1, 1){
int dx = abs(pt[i].F - pt[j].F), dy = abs(pt[i].S - pt[j].S);
int w = min({(dx + dy) * c, dx * c + dy * a + b, dy * c + dx * a + b});
edge[i].eb(j, w);
edge[j].eb(i, w);
}
}
Dijkstra();
/*
cerr<<"dis : ";
FOR(i, 1, n, 1){
cerr<<dis[i]<<" ";
}
cerr<<endl;
*/
cout<<dis[n]<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
1 ms |
2676 KB |
Output is correct |
5 |
Correct |
1 ms |
2636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2764 KB |
Output is correct |
3 |
Correct |
2 ms |
2892 KB |
Output is correct |
4 |
Correct |
2 ms |
2932 KB |
Output is correct |
5 |
Correct |
3 ms |
3532 KB |
Output is correct |
6 |
Correct |
46 ms |
20928 KB |
Output is correct |
7 |
Correct |
18 ms |
19020 KB |
Output is correct |
8 |
Correct |
17 ms |
19148 KB |
Output is correct |
9 |
Correct |
18 ms |
18976 KB |
Output is correct |
10 |
Correct |
17 ms |
18916 KB |
Output is correct |
11 |
Correct |
17 ms |
18928 KB |
Output is correct |
12 |
Correct |
2 ms |
3276 KB |
Output is correct |
13 |
Correct |
36 ms |
20992 KB |
Output is correct |
14 |
Correct |
17 ms |
18892 KB |
Output is correct |
15 |
Correct |
26 ms |
18952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2636 KB |
Output is correct |
2 |
Correct |
2 ms |
2636 KB |
Output is correct |
3 |
Correct |
1 ms |
2636 KB |
Output is correct |
4 |
Correct |
1 ms |
2676 KB |
Output is correct |
5 |
Correct |
1 ms |
2636 KB |
Output is correct |
6 |
Correct |
2 ms |
2636 KB |
Output is correct |
7 |
Correct |
2 ms |
2764 KB |
Output is correct |
8 |
Correct |
2 ms |
2892 KB |
Output is correct |
9 |
Correct |
2 ms |
2932 KB |
Output is correct |
10 |
Correct |
3 ms |
3532 KB |
Output is correct |
11 |
Correct |
46 ms |
20928 KB |
Output is correct |
12 |
Correct |
18 ms |
19020 KB |
Output is correct |
13 |
Correct |
17 ms |
19148 KB |
Output is correct |
14 |
Correct |
18 ms |
18976 KB |
Output is correct |
15 |
Correct |
17 ms |
18916 KB |
Output is correct |
16 |
Correct |
17 ms |
18928 KB |
Output is correct |
17 |
Correct |
2 ms |
3276 KB |
Output is correct |
18 |
Correct |
36 ms |
20992 KB |
Output is correct |
19 |
Correct |
17 ms |
18892 KB |
Output is correct |
20 |
Correct |
26 ms |
18952 KB |
Output is correct |
21 |
Correct |
1 ms |
2636 KB |
Output is correct |
22 |
Incorrect |
2 ms |
2892 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |