#include "wombats.h"
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
int n, m;
vector<vector<pair<int, int>>> g;
int calc[200][200];
int dist[5000 * 200];
bool used[5000 * 200];
const int inf = 2e9;
void djkstra(int v, vector<vector<pair<int, int>>> &g, int* arr) {
priority_queue<pair<int, int>> q;
fill(dist, dist + n * m, inf);
fill(used, used + n * m, false);
dist[v] = 0;
q.push({ -dist[v], v });
while (!q.empty()) {
int u = q.top().second;
q.pop();
if (used[u]) continue;
used[u] = true;
for (auto [c, w] : g[u]) {
if (dist[c] > dist[u] + w) {
dist[c] = dist[u] + w;
q.push({ -dist[c], c });
}
}
}
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, g, calc[i]);
}
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n = R;
m = C;
g.resize(n * m);
for (int i = 0; i < n; ++i) {
for (int j = 0; j + 1 < m; ++j) {
g[i * m + j].push_back({ i * m + j + 1, H[i][j] });
g[i * m + j + 1].push_back({ i * m + j, H[i][j] });
}
}
for (int i = 0; i + 1 < n; ++i) {
for (int j = 0; j < m; ++j) {
g[i * m + j].push_back({ i * m + j + m, V[i][j] });
}
}
recalc();
}
void changeH(int P, int Q, int W) {
g[P * m + Q][1].second = W;
g[P * m + Q + 1][0].second = W;
recalc();
}
void changeV(int P, int Q, int W) {
g[P * Q].back().second = W;
g[P * Q + m].back().second = W;
recalc();
}
int escape(int V1, int V2) {
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;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
62 ms |
4520 KB |
Output is correct |
2 |
Incorrect |
60 ms |
4532 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
296 KB |
Output is correct |
11 |
Correct |
68 ms |
2728 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11834 ms |
1392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
385 ms |
8788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12003 ms |
1388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11786 ms |
1388 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |