#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int B = 11, Cmax = 205, Rmax = 5005;
const int inf = 1e8;
int N, M, rm;
int h[Rmax][Cmax], v[Rmax][Cmax];
int opt[Cmax][Cmax];
static bool min_to(int &x, int y) { if(x < y) return 0; x = y; return 1; }
static void rec(int a[], int p)
{
int i;
for(i=1; i<M; ++i)
min_to(a[i], a[i-1] + h[p][i-1]);
for(i=M-2; i>=0; --i)
min_to(a[i], a[i+1] + h[p][i]);
}
struct matrix
{
int a[Cmax][Cmax];
void combine(matrix &A, matrix &B, int pos) /// knuth frumos
{
int i, k;
for(i=0; i<M; ++i)
{
a[i][i] = inf;
for(k=0; k<M; ++k)
if(min_to (a[i][i], A.a[i][k] + B.a[k][i] + v[pos][k]) )
opt[i][i] = k;
}
int j;
for(i=M-1; i>=0; --i)
for(j=i+1; j<M; ++j)
{
a[i][j] = inf;
for(k = opt[i][j-1]; k <= opt[i+1][j]; ++k)
if(min_to (a[i][j], A.a[i][k] + B.a[k][j] + v[pos][k]) )
opt[i][j] = k;
}
for(i=0; i<M; ++i)
for(j=i-1; j>=0; --j)
{
a[i][j] = inf;
for(k = opt[i-1][j]; k <= opt[i][j+1]; ++k)
if(min_to (a[i][j], A.a[i][k] + B.a[k][j] + v[pos][k]) )
opt[i][j] = k;
}
}
void refresh(int bucket)
{
int i, j, k;
for(i=0; i<M; ++i)
{
for(j=0; j<M; ++j)
a[i][j] = (i==j ? 0 : inf);
for(k = bucket * B; k < (bucket+1) * B && k < N; ++k)
{
rec(a[i], k);
if(k + 1 < min(B * (bucket+1), N))
for(j=0; j<M; ++j)
a[i][j] += v[k][j];
}
}
}
};
#define left_son (node<<1)
#define right_son ((node<<1)|1)
#define mid ((st+dr)>>1)
namespace aint
{
matrix a[ (Rmax / B + 3) << 2];
void update(int node, int st, int dr, int pos)
{
if(st == dr)
{
a[node].refresh(st);
return;
}
if(pos <= mid) update(left_son, st, mid, pos);
else update(right_son, mid+1, dr, pos);
a[node].combine(a[left_son], a[right_son], (mid+1) * B - 1);
}
void build(int node, int st, int dr)
{
if(st == dr)
{
a[node].refresh(st);
return;
}
build(left_son, st, mid);
build(right_son, mid+1, dr);
a[node].combine(a[left_son], a[right_son], (mid+1) * B - 1);
}
int get_answer(int start, int finish)
{
return a[1].a[start][finish];
}
};
void init(int R, int C, int H[5000][200], int V[5000][200])
{
N = R; M = C;
rm = (N-1) / B;
int i, j;
for(i=0; i<N; ++i)
for(j=0; j<M; ++j)
h[i][j] = H[i][j], v[i][j] = V[i][j];
aint::build(1, 0, rm);
}
void changeH(int P, int Q, int W)
{
h[P][Q] = W;
aint::update(1, 0, rm, P / B);
}
void changeV(int P, int Q, int W)
{
v[P][Q] = W;
aint::update(1, 0, rm, P / B);
}
int escape(int V1, int V2)
{
return aint::get_answer(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]
int res;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
16248 KB |
Output is correct |
2 |
Correct |
16 ms |
16248 KB |
Output is correct |
3 |
Correct |
87 ms |
17784 KB |
Output is correct |
4 |
Correct |
17 ms |
16248 KB |
Output is correct |
5 |
Correct |
16 ms |
16248 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
280 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
2 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
2 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
504 KB |
Output is correct |
11 |
Correct |
80 ms |
1528 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
2168 KB |
Output is correct |
2 |
Correct |
86 ms |
2172 KB |
Output is correct |
3 |
Correct |
112 ms |
2392 KB |
Output is correct |
4 |
Correct |
111 ms |
2296 KB |
Output is correct |
5 |
Correct |
114 ms |
2296 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
380 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
433 ms |
2384 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
20856 KB |
Output is correct |
2 |
Correct |
20 ms |
20856 KB |
Output is correct |
3 |
Correct |
21 ms |
20856 KB |
Output is correct |
4 |
Correct |
58 ms |
21728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
2168 KB |
Output is correct |
2 |
Correct |
86 ms |
2168 KB |
Output is correct |
3 |
Correct |
111 ms |
2300 KB |
Output is correct |
4 |
Correct |
111 ms |
2424 KB |
Output is correct |
5 |
Correct |
116 ms |
2424 KB |
Output is correct |
6 |
Correct |
20 ms |
20856 KB |
Output is correct |
7 |
Correct |
20 ms |
20856 KB |
Output is correct |
8 |
Correct |
20 ms |
20856 KB |
Output is correct |
9 |
Correct |
59 ms |
21624 KB |
Output is correct |
10 |
Correct |
16 ms |
16248 KB |
Output is correct |
11 |
Correct |
16 ms |
16248 KB |
Output is correct |
12 |
Correct |
87 ms |
17812 KB |
Output is correct |
13 |
Correct |
16 ms |
16248 KB |
Output is correct |
14 |
Correct |
16 ms |
16252 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
508 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
508 KB |
Output is correct |
25 |
Correct |
79 ms |
1528 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
432 ms |
2392 KB |
Output is correct |
28 |
Correct |
1068 ms |
93048 KB |
Output is correct |
29 |
Correct |
1147 ms |
76648 KB |
Output is correct |
30 |
Correct |
1144 ms |
76500 KB |
Output is correct |
31 |
Correct |
1086 ms |
94116 KB |
Output is correct |
32 |
Correct |
4 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
2216 KB |
Output is correct |
2 |
Correct |
86 ms |
2168 KB |
Output is correct |
3 |
Correct |
112 ms |
2296 KB |
Output is correct |
4 |
Correct |
111 ms |
2424 KB |
Output is correct |
5 |
Correct |
117 ms |
2404 KB |
Output is correct |
6 |
Correct |
21 ms |
20856 KB |
Output is correct |
7 |
Correct |
20 ms |
20856 KB |
Output is correct |
8 |
Correct |
21 ms |
20856 KB |
Output is correct |
9 |
Correct |
58 ms |
21688 KB |
Output is correct |
10 |
Correct |
16 ms |
16252 KB |
Output is correct |
11 |
Correct |
16 ms |
16248 KB |
Output is correct |
12 |
Correct |
88 ms |
17912 KB |
Output is correct |
13 |
Correct |
16 ms |
16248 KB |
Output is correct |
14 |
Correct |
16 ms |
16248 KB |
Output is correct |
15 |
Correct |
1423 ms |
165964 KB |
Output is correct |
16 |
Correct |
4403 ms |
168616 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
2 ms |
504 KB |
Output is correct |
24 |
Correct |
2 ms |
504 KB |
Output is correct |
25 |
Correct |
2 ms |
504 KB |
Output is correct |
26 |
Correct |
2 ms |
504 KB |
Output is correct |
27 |
Correct |
80 ms |
2884 KB |
Output is correct |
28 |
Correct |
2 ms |
504 KB |
Output is correct |
29 |
Correct |
430 ms |
2552 KB |
Output is correct |
30 |
Correct |
1079 ms |
96784 KB |
Output is correct |
31 |
Correct |
3787 ms |
174324 KB |
Output is correct |
32 |
Correct |
3774 ms |
174332 KB |
Output is correct |
33 |
Correct |
1152 ms |
80044 KB |
Output is correct |
34 |
Correct |
4061 ms |
144104 KB |
Output is correct |
35 |
Correct |
1145 ms |
79892 KB |
Output is correct |
36 |
Correct |
4051 ms |
144012 KB |
Output is correct |
37 |
Correct |
1087 ms |
98680 KB |
Output is correct |
38 |
Correct |
3927 ms |
174928 KB |
Output is correct |
39 |
Correct |
2 ms |
376 KB |
Output is correct |
40 |
Correct |
4077 ms |
144292 KB |
Output is correct |