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>
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';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |