#include "wombats.h"
#include <bits/stdc++.h>
constexpr const int BS = 9;
int r, c;
std::vector <std::vector <int>> h, v;
struct Block {
int sc = -1, ec = -1;
std::vector <std::vector <int>> con;
Block(bool empty = false) :
con(!empty * c, std::vector <int> (c, 1 << 30))
{ }
void update(int _sc, int _ec) {
sc = _sc;
ec = _ec;
for (int i = 0; i < c; i++) {
for (int j = 0; j < c; j++) {
con[i][j] = 1 << 30;
}
}
for (int j = 0; j < c; j++) {
con[j][j] = 0;
}
for (int i = ec; i >= sc; i--) {
std::vector <std::vector <int>> nxt(c, std::vector <int> (c, 1 << 30));
if (i == ec) {
for (int j = 0; j < c; j++) {
nxt[j][j] = 0;
}
}
for (int j = 0; j < c; j++) {
if (i != ec) {
for (int k = 0; k < c; k++) {
nxt[j][k] = std::min(nxt[j][k], con[j][k] + v[i][j]);
}
}
if (j) {
for (int k = 0; k < c; k++) {
nxt[j][k] = std::min(nxt[j][k], nxt[j - 1][k] + h[i][j - 1]);
}
}
}
for (int j = c - 1; j >= 0; j--) {
if (j + 1 < c) {
for (int k = 0; k < c; k++) {
nxt[j][k] = std::min(nxt[j][k], nxt[j + 1][k] + h[i][j]);
}
}
}
std::swap(con, nxt);
}
}
friend Block merge(const Block& upper, const Block& lower) {
if (!upper.con.empty() && lower.con.empty()) {
return upper;
}
if (upper.con.empty()) {
assert(lower.con.empty());
return Block(true);
}
Block res;
res.sc = upper.sc;
res.ec = lower.ec;
std::vector <std::vector <int>> ine(c, std::vector <int> (c, 1 << 30));
{
for (int j = 0; j < c; j++) {
for (int k = 0; k < c; k++) {
ine[j][k] = std::min(ine[j][k], lower.con[j][k] + v[upper.ec][j]);
}
if (j) {
for (int k = 0; k < c; k++) {
ine[j][k] = std::min(ine[j][k], ine[j - 1][k] + h[upper.ec][j - 1]);
}
}
}
for (int j = c - 1; j >= 0; j--) {
if (j + 1 < c) {
for (int k = 0; k < c; k++) {
ine[j][k] = std::min(ine[j][k], ine[j + 1][k] + h[upper.ec][j]);
}
}
}
}
for (int i = 0; i < c; i++) {
for (int j = 0; j < c; j++) {
for (int k = 0; k < c; k++) {
res.con[i][k] = std::min(res.con[i][k], upper.con[i][j] + ine[j][k]);
}
}
}
return res;
}
};
struct Seg {
int size;
std::vector <Block> v;
Seg(int s) {
size = 1;
while (size < s) {
size <<= 1;
}
v.resize(size << 1, Block(true));
build(0, 0, size);
}
void build(int now, int li, int ri) {
if (!(ri - li - 1)) {
if (li * BS < r) {
v[now] = Block();
v[now].update(li * BS, std::min(r - 1, (li + 1) * BS - 1));
}
return;
}
int mid = (li + ri) >> 1;
build(now * 2 + 1, li, mid);
build(now * 2 + 2, mid, ri);
v[now] = merge(v[now * 2 + 1], v[now * 2 + 2]);
}
void update(int ind) {
update(ind, 0, 0, size);
}
void update(int ind, int now, int li, int ri) {
if (!(ri - li - 1)) {
v[now].update(ind * BS, std::min(r - 1, (ind + 1) * BS - 1));
return;
}
int mid = (li + ri) >> 1;
if (ind < mid) {
update(ind, now * 2 + 1, li, mid);
} else {
update(ind, now * 2 + 2, mid, ri);
}
v[now] = merge(v[now * 2 + 1], v[now * 2 + 2]);
}
};
Seg* seg;
void init(int R, int C, int H[5000][200], int V[5000][200]) {
r = R;
c = C;
h.resize(r, std::vector <int> (c - 1));
v.resize(r - 1, std::vector <int> (c));
for (int i = 0; i < r; i++) {
for (int j = 0; j < c; j++) {
if (j < c - 1) {
h[i][j] = H[i][j];
}
if (i < r - 1) {
v[i][j] = V[i][j];
}
}
}
seg = new Seg((r + BS - 1) / BS);
}
void changeH(int p, int q, int w) {
h[p][q] = w;
seg->update(p / BS);
}
void changeV(int p, int q, int w) {
v[p][q] = w;
seg->update(p / BS);
}
int escape(int v1, int v2) {
return seg->v[0].con[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;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4692 KB |
Output is correct |
2 |
Correct |
4 ms |
4708 KB |
Output is correct |
3 |
Correct |
67 ms |
6244 KB |
Output is correct |
4 |
Correct |
6 ms |
4692 KB |
Output is correct |
5 |
Correct |
5 ms |
4692 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
64 ms |
1332 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
343 ms |
1620 KB |
Output is correct |
2 |
Correct |
450 ms |
1620 KB |
Output is correct |
3 |
Correct |
443 ms |
1796 KB |
Output is correct |
4 |
Correct |
456 ms |
1672 KB |
Output is correct |
5 |
Correct |
447 ms |
1744 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
2259 ms |
1676 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
8788 KB |
Output is correct |
2 |
Correct |
8 ms |
8788 KB |
Output is correct |
3 |
Correct |
9 ms |
8876 KB |
Output is correct |
4 |
Correct |
42 ms |
9640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
331 ms |
1612 KB |
Output is correct |
2 |
Correct |
463 ms |
1728 KB |
Output is correct |
3 |
Correct |
501 ms |
1804 KB |
Output is correct |
4 |
Correct |
431 ms |
1672 KB |
Output is correct |
5 |
Correct |
459 ms |
1736 KB |
Output is correct |
6 |
Correct |
8 ms |
8880 KB |
Output is correct |
7 |
Correct |
9 ms |
8856 KB |
Output is correct |
8 |
Correct |
8 ms |
8788 KB |
Output is correct |
9 |
Correct |
39 ms |
9628 KB |
Output is correct |
10 |
Correct |
5 ms |
4692 KB |
Output is correct |
11 |
Correct |
6 ms |
4692 KB |
Output is correct |
12 |
Correct |
68 ms |
6316 KB |
Output is correct |
13 |
Correct |
4 ms |
4692 KB |
Output is correct |
14 |
Correct |
4 ms |
4692 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
81 ms |
1228 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2272 ms |
1668 KB |
Output is correct |
28 |
Correct |
5672 ms |
61344 KB |
Output is correct |
29 |
Correct |
5660 ms |
50344 KB |
Output is correct |
30 |
Correct |
5387 ms |
50152 KB |
Output is correct |
31 |
Correct |
6342 ms |
62240 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
341 ms |
1620 KB |
Output is correct |
2 |
Correct |
503 ms |
1612 KB |
Output is correct |
3 |
Correct |
456 ms |
1868 KB |
Output is correct |
4 |
Correct |
447 ms |
1680 KB |
Output is correct |
5 |
Correct |
456 ms |
1664 KB |
Output is correct |
6 |
Correct |
7 ms |
8788 KB |
Output is correct |
7 |
Correct |
8 ms |
8788 KB |
Output is correct |
8 |
Correct |
8 ms |
8788 KB |
Output is correct |
9 |
Correct |
43 ms |
9616 KB |
Output is correct |
10 |
Correct |
5 ms |
4692 KB |
Output is correct |
11 |
Correct |
4 ms |
4692 KB |
Output is correct |
12 |
Correct |
69 ms |
6212 KB |
Output is correct |
13 |
Correct |
4 ms |
4692 KB |
Output is correct |
14 |
Correct |
5 ms |
4620 KB |
Output is correct |
15 |
Correct |
5711 ms |
200196 KB |
Output is correct |
16 |
Execution timed out |
20091 ms |
201108 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |