Submission #1159756

#TimeUsernameProblemLanguageResultExecution timeMemory
1159756HakunaSoccer (JOI17_soccer)C++20
5 / 100
0 ms328 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int h, w;
    cin >> h >> w;
    int a, b, c;
    cin >> a >> b >> c;
    int n;
    cin >> n;
    int x[n + 1], y[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> x[i] >> y[i];
    }
    
    long long ans = 0;
    if (x[1] != x[n] && y[1] != y[n]) {
        if (abs(x[1] - x[n]) > abs(y[1] - y[n])) {
            ans += c *1ll* abs(y[1] - y[n]);
            y[1] = y[n];
        } else {
            ans += c *1ll* abs(x[1] - x[n]);
            x[1] = x[n];
        }
    }
    
    long long dist = (abs(x[1] - x[n]) + abs(y[1] - y[n]));
    if (dist * c < dist * a + b) {
        ans += dist * c;
    } else {
        ans += dist * a + b;
    }
    cout << ans;

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...