#include <bits/stdc++.h>
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
using namespace std;
const int dx[] = {-1, 1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const int N = 505;
int n, m, k;
int A, B, C;
int dist[N][N];
long long d[N * N * 3];
pair<int, int> pos[100005];
vector<pair<int, long long>> g[N * N * 3];
struct state {
int u;
long long w;
bool operator < (const state& o) const {
return w > o.w;
}
};
priority_queue<state> pq;
bool inBoard(int x, int y) {
return 0 <= x && x <= n && 0 <= y && y <= m;
}
int con(int i, int j) {
return i * (m + 1) + j;
}
int v1(int i, int j) {
return con(i, j);
}
int v2(int i, int j) {
return con(i, j) + (n + 1) * (m + 1);
}
int v3(int i, int j) {
return con(i, j) + 2 * (n + 1) * (m + 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
file("A") else file("task");
cin >> n >> m;
cin >> A >> B >> C;
cin >> k;
memset(dist, -1, sizeof dist);
queue<pair<int, int>> q;
for(int _ = 1; _ <= k; ++_) {
int x, y;
cin >> x >> y;
pos[_] = make_pair(x, y);
dist[x][y] = 0;
q.emplace(x, y);
}
while(!q.empty()) {
auto [x, y] = q.front();
q.pop();
for(int _ = 0; _ < 4; ++_) {
int nx = x + dx[_];
int ny = y + dy[_];
if(!inBoard(nx, ny) || dist[nx][ny] != -1) continue;
dist[nx][ny] = dist[x][y] + 1;
q.emplace(nx, ny);
}
}
for(int i = 0; i <= n; ++i) {
for(int j = 0; j <= m; ++j) {
g[v3(i, j)].emplace_back(v1(i, j), B);
g[v3(i, j)].emplace_back(v2(i, j), B);
if(j < m) g[v1(i, j)].emplace_back(v1(i, j + 1), A), g[v1(i, j + 1)].emplace_back(v1(i, j), A);
if(i < n) g[v2(i, j)].emplace_back(v2(i + 1, j), A), g[v2(i + 1, j)].emplace_back(v2(i, j), A);
if(j < m) g[v3(i, j)].emplace_back(v3(i, j + 1), C), g[v3(i, j + 1)].emplace_back(v3(i, j), C);
if(i < n) g[v3(i, j)].emplace_back(v3(i + 1, j), C), g[v3(i + 1, j)].emplace_back(v3(i, j), C);
g[v1(i, j)].emplace_back(v3(i, j), (long long) C * dist[i][j]);
g[v2(i, j)].emplace_back(v3(i, j), (long long) C * dist[i][j]);
}
}
memset(d, 0x3f, sizeof d);
pq.push({v3(pos[1].first, pos[1].second), 0});
d[v3(pos[1].first, pos[1].second)] = 0;
while(!pq.empty()) {
auto [u, kc] = pq.top();
pq.pop();
if(d[u] != kc) continue;
for(auto [v, w] : g[u]) {
if(d[v] > d[u] + w) {
d[v] = d[u] + w;
pq.push({v, d[v]});
}
}
}
cout << d[v3(pos[k].first, pos[k].second)] << '\n';
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
soccer.cpp: In function 'int main()':
soccer.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:42:5: note: in expansion of macro 'file'
42 | file("A") else file("task");
| ^~~~
soccer.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:42:5: note: in expansion of macro 'file'
42 | file("A") else file("task");
| ^~~~
soccer.cpp:2:58: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:42:20: note: in expansion of macro 'file'
42 | file("A") else file("task");
| ^~~~
soccer.cpp:2:91: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
2 | #define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
soccer.cpp:42:20: note: in expansion of macro 'file'
42 | file("A") else file("task");
| ^~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |