#include "wombats.h"
#include <algorithm>
#include <vector>
#include <queue>
#include <cassert>
using namespace std;
int n, m;
int h[5000][200];
int v[5000][200];
int calc[200][200];
int dist[5000 * 200];
bool used[5000 * 200];
const int inf = 2e9;
void djkstra(int s, int* arr) {
priority_queue<pair<int, int>> q;
fill(dist, dist + n * m, inf);
fill(used, used + n * m, false);
dist[s] = 0;
q.push({ -dist[s], s });
while (!q.empty()) {
int u = q.top().second;
q.pop();
if (used[u]) continue;
used[u] = true;
int r = u / m;
int c = u % m;
if (r + 1 < n && dist[u + m] > dist[u] + v[r][c]) {
dist[u + m] = dist[u] + v[r][c];
q.push({ -dist[u + m], u + m });
}
if (c > 0 && dist[u - 1] > dist[u] + h[r][c - 1]) {
dist[u - 1] = dist[u] + h[r][c - 1];
q.push({ -dist[u - 1], u - 1 });
}
if (c + 1 < m && dist[u + 1] > dist[u] + h[r][c]) {
dist[u + 1] = dist[u] + h[r][c];
q.push({ -dist[u], u });
}
}
for (int i = (n - 1) * m; i < n * m; ++i) {
arr[i - (n - 1) * m] = dist[i];
}
}
void recalc() {
for (int i = 0; i < m; ++i) {
djkstra(i, calc[i]);
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R;
m = C;
for (int i = 0; i < 5000; ++i) {
memcpy(h, H, 200 * sizeof(int));
}
for (int i = 0; i < 5000; ++i) {
memcpy(v, V, 200 * sizeof(int));
}
recalc();
}
void changeH(int P, int Q, int W) {
h[P][Q] = W;
recalc();
}
void changeV(int P, int Q, int W) {
v[P][Q] = W;
recalc();
}
int escape(int V1, int V2) {
assert(V1 < m);
assert(V2 < m);
return calc[V1][V2];
}
Compilation message
grader.c: In function 'int main()':
grader.c:15:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
15 | int res;
| ^~~
wombats.cpp: In function 'void init(int, int, int (*)[200], int (*)[200])':
wombats.cpp:59:9: error: 'memcpy' was not declared in this scope
59 | memcpy(h, H, 200 * sizeof(int));
| ^~~~~~
wombats.cpp:6:1: note: 'memcpy' is defined in header '<cstring>'; did you forget to '#include <cstring>'?
5 | #include <cassert>
+++ |+#include <cstring>
6 |
wombats.cpp:62:9: error: 'memcpy' was not declared in this scope
62 | memcpy(v, V, 200 * sizeof(int));
| ^~~~~~
wombats.cpp:62:9: note: 'memcpy' is defined in header '<cstring>'; did you forget to '#include <cstring>'?