#include <algorithm>
#include <numeric>
#include <queue>
#include <vector>
#include "wombats.h"
#define entire(a) std::begin((a)), std::end((a))
std::vector<std::vector<int>> h, v;
int r, c;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
h.reserve(R);
v.reserve(R);
for (int i = 0; i < R; i++) {
h.emplace_back(entire(H[i]));
v.emplace_back(entire(V[i]));
}
r = R;
c = C;
}
void changeH(int P, int Q, int W) { h[P][Q] = W; }
void changeV(int P, int Q, int W) { v[P][Q] = W; }
int escape(int V1, int V2) {
std::vector<int> dist(c, 0);
dist[V1] = 0;
for (int i = V1 + 1; i < r; i++) {
dist[i] = dist[i - 1] + h[0][i - 1];
}
for (int i = V1 - 1; i >= 0; i--) {
dist[i] = dist[i + 1] + h[0][i];
}
// ...
std::priority_queue<std::pair<int, int>> pq;
for (int i = 0; i + 1 < r; i++) {
// phase 1: process vertical segments
for (int j = 0; j < c; j++) {
dist[j] += v[i][j];
}
// phase 2: process horizontal segments
while (!pq.empty()) pq.pop(); // whyy is there no pq.clear();
for (int j = 0; j < c; j++) {
pq.push({-dist[j], j});
}
while (!pq.empty()) {
auto [d, j] = pq.top();
pq.pop();
d = -d;
if (d > dist[j]) continue;
if (j > 0 && dist[j - 1] > d + h[i + 1][j - 1]) {
dist[j - 1] = d + h[i + 1][j - 1];
pq.push({-dist[j - 1], j - 1});
}
if (j + 1 < c && dist[j + 1] > d + h[i + 1][j]) {
dist[j + 1] = d + h[i + 1][j];
pq.push({-dist[j + 1], j + 1});
}
}
}
return dist[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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
18 ms |
24972 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
260 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
8 ms |
340 KB |
Output is correct |
5 |
Correct |
4 ms |
340 KB |
Output is correct |
6 |
Correct |
4 ms |
340 KB |
Output is correct |
7 |
Correct |
7 ms |
380 KB |
Output is correct |
8 |
Correct |
8 ms |
372 KB |
Output is correct |
9 |
Incorrect |
9 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
93 ms |
608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
24 ms |
32868 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
92 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
93 ms |
600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |