#include <bits/stdc++.h>
using namespace std;
#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(0);
using ll = int64_t;
using ull = uint64_t;
using uint = uint32_t;
using ld = long double;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const ll LINF = ll(4e18) + ll(2e15);
const double EPS = 1e-9;
static int LamyIsCute = []() {
EmiliaMyWife
return 48763;
}();
signed main() {
int h, w;
cin >> h >> w;
ll a, b, c;
cin >> a >> b >> c;
int n;
cin >> n;
vector<pair<int, int>> arr(n);
for(int i = 0; i < n; i++)
cin >> arr[i].first >> arr[i].second;
vector<vector<ll>> edge(n, vector<ll>(n, LINF));
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
ll x = abs(arr[i].first - arr[j].first), y = abs(arr[i].second - arr[j].second);
edge[i][j] = min(edge[i][j], c * (x + y));
edge[i][j] = min(edge[i][j], c * x + y * a + b);
edge[i][j] = min(edge[i][j], c * y + x * a + b);
}
}
vector<ll> dis(n, LINF);
vector<bool> vis(n);
dis[0] = 0;
while(true) {
int u = -1;
for(int i = 0; i < n; i++)
if(!vis[i] && (u == -1 || dis[u] > dis[i]))
u = i;
if(u == -1)
break;
vis[u] = true;
for(int v = 0; v < n; v++)
dis[v] = min(dis[v], dis[u] + edge[u][v]);
}
cout << dis[n - 1] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
308 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
588 KB |
Output is correct |
6 |
Correct |
16 ms |
8140 KB |
Output is correct |
7 |
Correct |
11 ms |
8124 KB |
Output is correct |
8 |
Correct |
13 ms |
8160 KB |
Output is correct |
9 |
Correct |
12 ms |
8140 KB |
Output is correct |
10 |
Correct |
12 ms |
8140 KB |
Output is correct |
11 |
Correct |
13 ms |
8140 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
12 ms |
8268 KB |
Output is correct |
14 |
Correct |
13 ms |
8232 KB |
Output is correct |
15 |
Correct |
13 ms |
8200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
588 KB |
Output is correct |
11 |
Correct |
16 ms |
8140 KB |
Output is correct |
12 |
Correct |
11 ms |
8124 KB |
Output is correct |
13 |
Correct |
13 ms |
8160 KB |
Output is correct |
14 |
Correct |
12 ms |
8140 KB |
Output is correct |
15 |
Correct |
12 ms |
8140 KB |
Output is correct |
16 |
Correct |
13 ms |
8140 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
12 ms |
8268 KB |
Output is correct |
19 |
Correct |
13 ms |
8232 KB |
Output is correct |
20 |
Correct |
13 ms |
8200 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |