#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9+7;
ll binpow(ll base, ll exp, ll mod) {
ll result = 1;
base %= mod;
while (exp > 0) {
if (exp & 1) result = (result * base) % mod;
base = (base * base) % mod;
exp >>= 1;
}
return result;
}
vector<ll> fact, invfact;
void pre_fact(int MAXN) {
fact.resize(MAXN + 5, 1);
invfact.resize(MAXN + 5, 1);
for (int i = 2; i <= MAXN; i++)
fact[i] = (fact[i-1] * i) % mod;
invfact[MAXN] = binpow(fact[MAXN], mod-2, mod);
for (int i = MAXN-1; i > 0; i--)
invfact[i] = (invfact[i+1] * (i+1)) % mod;
invfact[0] = 1;
}
ll C(ll n, ll k) {
if (k > n || k < 0) return 0;
return fact[n] * invfact[k] % mod * invfact[n-k] % mod;
}
void dfs(vector<vector<int>>& g, int u, vector<int>& vis, vector<int>& order){
vis[u] = 1;
for (int e: g[u]){
if (vis[e]==0) dfs(g, e, vis, order);
}
order.push_back(u);
}
vector<int> topsort(vector<vector<int>>& g){
int n = g.size();
vector<int> order;
vector<int> vis(n);
for (int i = 0; i<n; i++){
if (vis[i]==0) dfs(g, i, vis, order);
}
return order;
}
int main() {
int h, w; cin>>h>>w;
ll a, b, c; cin>>a>>b>>c;
int n; cin>>n;
if (n==2){
int x, y; cin>>x>>y;
int xx, yy; cin>>xx>>yy;
int res = min({(abs(x-xx)+abs(y-yy))*c, abs(x-xx)*c+abs(y-yy)*a+b, abs(y-yy)*c+abs(x-xx)*a+b});
cout<<res;
}
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |