#include<bits/stdc++.h>
#define debug(x) cout << "\033[36m"<< __LINE__ << ":\033[39m " << (#x) << " = " << (x) << '\n'
#define F first
#define S second
const char nl = '\n';
using namespace std;
using ll = long long;
ll h, w;
ll A, B, C;
ll n;
vector<pair<ll, ll>> vp(100010);
ll dp[510][510];
ll dist(ll x, ll y, ll X, ll Y) {
return abs(x - X) + abs(y - Y);
}
ll shoot(ll x, ll y, ll X, ll Y) {
ll res1 = abs(x - X)*C;
ll res2 = abs(y - Y)*C;
res1 += A*dist(X, y, X, Y) + B;
res2 += A*dist(x, Y, X, Y) + B;
// cout << abs(x - X) << " " << dist(X, y, X, Y) << nl;
// cout << abs(y - Y) << " " << dist(x, Y, X, Y) << nl;
return min(res1, res2);
}
void solve() {
cin >> h >> w;
cin >> A >> B >> C;
cin >> n;
for (ll i = 1; i <= n; i ++) {
cin >> vp[i].F >> vp[i].S;
}
for (ll i = 0; i <= 500; i ++) {
for (ll j = 0; j <= 500; j ++) {
dp[i][j] = dist(vp[1].F, vp[1].S, i, j) * C;
}
}
cout << min({dp[vp[2].F][vp[2].S], shoot(vp[1].F, vp[1].S, vp[2].F, vp[2].S)});
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll tst = 1;
// cin >> tst;
while (tst --) {
solve();
cout << nl;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
2 ms |
3932 KB |
Output is correct |
4 |
Correct |
2 ms |
3932 KB |
Output is correct |
5 |
Correct |
2 ms |
3932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3928 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
3932 KB |
Output is correct |
2 |
Correct |
2 ms |
3932 KB |
Output is correct |
3 |
Correct |
2 ms |
3932 KB |
Output is correct |
4 |
Correct |
2 ms |
3932 KB |
Output is correct |
5 |
Correct |
2 ms |
3932 KB |
Output is correct |
6 |
Incorrect |
2 ms |
3928 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |