#include <bits/stdc++.h>
#include "wombats.h"
#define ll long long
#define ull unsigned ll
#define f first
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const int nmax = 251;
int h[5000][200];
int v[5000][200];
int r, c;
int s;
struct node{
//vector <int> h;
vector <int> w;
vector <vector <int> > cost;
node(){
cost.resize(c);
for(int i = 0; i < c; i++)
cost[i].resize(c);
w.resize(c);
}
node(int c){
cost.resize(c);
for(int i = 0; i < c; i++)
cost[i].resize(c);
w.resize(c);
}
}t[4 * nmax];
node b[nmax];
node merg(node a, node b){
node c;
c.w = b.w;
int n = a.w.size();
c.cost.resize(n);
vector <vector <int> > opt;
opt.resize(n);
for(int i= 0; i < n; i++)
c.cost[i].resize(n), opt[i].resize(n);
for(int i = 0; i < n; i++){
int mn = 1e9 + 1, mni;
for(int j= 0; j < n; j++){
int val = a.cost[n - 1][j] + a.w[j] + b.cost[j][i];
if(val < mn)
mn = val, mni = j;
}
opt[n - 1][i] = mni, c.cost[n - 1][i] = mn;
}
for(int i = n - 2; i >= 0; i--){
int mn = 1e9 + 1,mni;
for(int j = 0; j < n; j++){
int val = a.cost[i][j] + a.w[j] + b.cost[j][0];
if(val < mn)
mn = val, mni = j;
}
opt[i][0] = mni, c.cost[i][0] = mn;
for(int j = 1; j <= n - 1; j++){
int mn = 1e9 + 1, mni = j;
for(int x = opt[i][j - 1]; x <= opt[i + 1][j]; x++){
int val = a.cost[i][x] + a.w[x] + b.cost[x][j];
if(val < mn)
mn = val, mni = x;
}
opt[i][j] = mni, c.cost[i][j] = mn;
}
}
return c;
}
void update(int v, int l, int r, int pos, node a){
if(l > pos || r < pos)
return;
if(l == r){
t[v] = a;
return;
}
int m = (l + r) / 2;
update(2 * v, l, m, pos, a);
update(2 * v + 1, m + 1, r, pos, a);
t[v] = merg(t[2 * v], t[2 * v + 1]);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
/* ... */
r = R, c = C;
for(int i = 0; i < 5000; i++){
for(int j = 0; j < 200; j++)
h[i][j] = H[i][j], v[i][j] = V[i][j];
}
for(int i = 0; i < r; i++){
node a = {c};
for(int j = 0; j < c; j++)
a.w[j] = V[i][j];
for(int x = 0; x < c; x++){
a.cost[x][x] = 0;
for(int y = x + 1; y < c; ++y){
a.cost[x][y] = a.cost[x][y - 1] + H[i][y - 1];
}
for(int y = x - 1; y >= 0; y--)
a.cost[x][y] = a.cost[x][y + 1] + H[i][y];
}
if(i % 20 == 0)
b[i / 20] = a;
else b[i / 20] = merg(b[i / 20], a);
s = i / 20;
}
for(int i = 0; i <= 3 * s; i++)
t[i] = {c};
for(int i = 0; i <= s; i++)
update(1, 0, s, i, b[i]);
}
void update_block(int o){
// b[o] = a[o * 10];
int xx = o * 20;
for(int i = xx; i < min(r, xx + 20); i++){
node a = {c};
for(int j = 0; j < c; j++)
a.w[j] = v[i][j];
for(int x = 0; x < c; x++){
a.cost[x][x] = 0;
for(int y = x + 1; y < c; ++y){
a.cost[x][y] = a.cost[x][y - 1] + h[i][y - 1];
}
for(int y = x - 1; y >= 0; y--)
a.cost[x][y] = a.cost[x][y + 1] + h[i][y];
}
if(i % 20 == 0)
b[i / 20] = a;
else b[i / 20] = merg(b[i / 20], a);
}
update(1, 0, s, o, b[o]);
}
void changeH(int p, int q, int w) {
/* ... */
h[p][q] = w;
update_block(p / 20);
}
void changeV(int p, int q, int w) {
/* ... */
v[p][q] = w;
update_block(p / 20);
}
int escape(int V1, int V2) {
return t[1].cost[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 'node merg(node, node)':
wombats.cpp:61:19: warning: 'mni' may be used uninitialized in this function [-Wmaybe-uninitialized]
61 | opt[i][0] = mni, c.cost[i][0] = mn;
wombats.cpp:52:23: warning: 'mni' may be used uninitialized in this function [-Wmaybe-uninitialized]
52 | opt[n - 1][i] = mni, c.cost[n - 1][i] = mn;
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
12116 KB |
Output is correct |
2 |
Correct |
17 ms |
12212 KB |
Output is correct |
3 |
Correct |
69 ms |
13724 KB |
Output is correct |
4 |
Correct |
14 ms |
12120 KB |
Output is correct |
5 |
Correct |
15 ms |
12116 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
5 ms |
8148 KB |
Output is correct |
8 |
Correct |
5 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
5 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8148 KB |
Output is correct |
4 |
Correct |
5 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8216 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
5 ms |
8184 KB |
Output is correct |
8 |
Correct |
5 ms |
8148 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
58 ms |
9232 KB |
Output is correct |
12 |
Correct |
5 ms |
8244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
254 ms |
9432 KB |
Output is correct |
2 |
Correct |
208 ms |
9428 KB |
Output is correct |
3 |
Correct |
257 ms |
9448 KB |
Output is correct |
4 |
Correct |
264 ms |
9444 KB |
Output is correct |
5 |
Correct |
256 ms |
9424 KB |
Output is correct |
6 |
Correct |
4 ms |
8148 KB |
Output is correct |
7 |
Correct |
4 ms |
8148 KB |
Output is correct |
8 |
Correct |
5 ms |
8148 KB |
Output is correct |
9 |
Correct |
1070 ms |
9548 KB |
Output is correct |
10 |
Correct |
4 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
16168 KB |
Output is correct |
2 |
Correct |
18 ms |
16176 KB |
Output is correct |
3 |
Correct |
18 ms |
16176 KB |
Output is correct |
4 |
Correct |
46 ms |
16936 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
247 ms |
9432 KB |
Output is correct |
2 |
Correct |
216 ms |
9424 KB |
Output is correct |
3 |
Correct |
258 ms |
9440 KB |
Output is correct |
4 |
Correct |
260 ms |
9452 KB |
Output is correct |
5 |
Correct |
278 ms |
9428 KB |
Output is correct |
6 |
Correct |
18 ms |
16084 KB |
Output is correct |
7 |
Correct |
18 ms |
16068 KB |
Output is correct |
8 |
Correct |
18 ms |
16128 KB |
Output is correct |
9 |
Correct |
46 ms |
16884 KB |
Output is correct |
10 |
Correct |
13 ms |
12200 KB |
Output is correct |
11 |
Correct |
13 ms |
12116 KB |
Output is correct |
12 |
Correct |
66 ms |
13760 KB |
Output is correct |
13 |
Correct |
18 ms |
12116 KB |
Output is correct |
14 |
Correct |
17 ms |
12204 KB |
Output is correct |
15 |
Correct |
5 ms |
8148 KB |
Output is correct |
16 |
Correct |
5 ms |
8104 KB |
Output is correct |
17 |
Correct |
5 ms |
8152 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
5 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
5 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8148 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
5 ms |
8148 KB |
Output is correct |
25 |
Correct |
59 ms |
9116 KB |
Output is correct |
26 |
Correct |
5 ms |
8148 KB |
Output is correct |
27 |
Correct |
1047 ms |
9468 KB |
Output is correct |
28 |
Correct |
2063 ms |
60324 KB |
Output is correct |
29 |
Correct |
2296 ms |
51276 KB |
Output is correct |
30 |
Correct |
2236 ms |
50984 KB |
Output is correct |
31 |
Correct |
2028 ms |
61472 KB |
Output is correct |
32 |
Correct |
5 ms |
8148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
249 ms |
9428 KB |
Output is correct |
2 |
Correct |
211 ms |
9436 KB |
Output is correct |
3 |
Correct |
260 ms |
9448 KB |
Output is correct |
4 |
Correct |
257 ms |
9440 KB |
Output is correct |
5 |
Correct |
255 ms |
9428 KB |
Output is correct |
6 |
Correct |
18 ms |
16172 KB |
Output is correct |
7 |
Correct |
18 ms |
16084 KB |
Output is correct |
8 |
Correct |
23 ms |
16176 KB |
Output is correct |
9 |
Correct |
56 ms |
16868 KB |
Output is correct |
10 |
Correct |
14 ms |
12116 KB |
Output is correct |
11 |
Correct |
14 ms |
12120 KB |
Output is correct |
12 |
Correct |
65 ms |
13728 KB |
Output is correct |
13 |
Correct |
13 ms |
12116 KB |
Output is correct |
14 |
Correct |
13 ms |
12116 KB |
Output is correct |
15 |
Correct |
2783 ms |
192640 KB |
Output is correct |
16 |
Correct |
8682 ms |
193944 KB |
Output is correct |
17 |
Correct |
5 ms |
8148 KB |
Output is correct |
18 |
Correct |
5 ms |
8148 KB |
Output is correct |
19 |
Correct |
5 ms |
8148 KB |
Output is correct |
20 |
Correct |
5 ms |
8148 KB |
Output is correct |
21 |
Correct |
5 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8148 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
5 ms |
8208 KB |
Output is correct |
25 |
Correct |
6 ms |
8384 KB |
Output is correct |
26 |
Correct |
5 ms |
8148 KB |
Output is correct |
27 |
Correct |
59 ms |
10540 KB |
Output is correct |
28 |
Correct |
5 ms |
8148 KB |
Output is correct |
29 |
Correct |
1020 ms |
9564 KB |
Output is correct |
30 |
Correct |
2098 ms |
64160 KB |
Output is correct |
31 |
Correct |
7440 ms |
191360 KB |
Output is correct |
32 |
Correct |
7423 ms |
191332 KB |
Output is correct |
33 |
Correct |
2359 ms |
54532 KB |
Output is correct |
34 |
Correct |
7835 ms |
159880 KB |
Output is correct |
35 |
Correct |
2225 ms |
54560 KB |
Output is correct |
36 |
Correct |
8057 ms |
159620 KB |
Output is correct |
37 |
Correct |
2139 ms |
65748 KB |
Output is correct |
38 |
Correct |
7640 ms |
192072 KB |
Output is correct |
39 |
Correct |
5 ms |
8148 KB |
Output is correct |
40 |
Correct |
8211 ms |
159896 KB |
Output is correct |