#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
const int B = 100, Cmax = 205, Rmax = 5005;
const int inf = 1e8;
int N, M, rm;
int h[Rmax][Cmax], v[Rmax][Cmax];
static void min_to(int &x, int y) { if(x > y) x = y ;}
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)
{
int i, j, k;
for(i=0; i<M; ++i)
for(j=0; j<M; ++j)
{
a[i][j] = inf;
for(k=0; k<M; ++k)
min_to(a[i][j], A.a[i][k] + B.a[k][j] + v[pos][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;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
12664 KB |
Output is correct |
2 |
Correct |
14 ms |
12716 KB |
Output is correct |
3 |
Correct |
84 ms |
15480 KB |
Output is correct |
4 |
Correct |
14 ms |
12664 KB |
Output is correct |
5 |
Correct |
14 ms |
12792 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 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
504 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
81 ms |
1440 KB |
Output is correct |
12 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
905 ms |
816 KB |
Output is correct |
2 |
Correct |
466 ms |
888 KB |
Output is correct |
3 |
Correct |
925 ms |
888 KB |
Output is correct |
4 |
Correct |
910 ms |
792 KB |
Output is correct |
5 |
Correct |
892 ms |
760 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 |
380 KB |
Output is correct |
9 |
Correct |
2795 ms |
860 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
18 ms |
16760 KB |
Output is correct |
2 |
Correct |
17 ms |
16760 KB |
Output is correct |
3 |
Correct |
19 ms |
16760 KB |
Output is correct |
4 |
Correct |
57 ms |
18168 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
906 ms |
792 KB |
Output is correct |
2 |
Correct |
461 ms |
792 KB |
Output is correct |
3 |
Correct |
913 ms |
860 KB |
Output is correct |
4 |
Correct |
897 ms |
792 KB |
Output is correct |
5 |
Correct |
892 ms |
792 KB |
Output is correct |
6 |
Correct |
18 ms |
16632 KB |
Output is correct |
7 |
Correct |
18 ms |
16760 KB |
Output is correct |
8 |
Correct |
19 ms |
16764 KB |
Output is correct |
9 |
Correct |
56 ms |
18244 KB |
Output is correct |
10 |
Correct |
14 ms |
12664 KB |
Output is correct |
11 |
Correct |
14 ms |
12792 KB |
Output is correct |
12 |
Correct |
85 ms |
15608 KB |
Output is correct |
13 |
Correct |
14 ms |
12792 KB |
Output is correct |
14 |
Correct |
14 ms |
12664 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
0 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
504 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 |
376 KB |
Output is correct |
22 |
Correct |
3 ms |
504 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
83 ms |
2800 KB |
Output is correct |
26 |
Correct |
3 ms |
376 KB |
Output is correct |
27 |
Correct |
2824 ms |
888 KB |
Output is correct |
28 |
Correct |
7431 ms |
28868 KB |
Output is correct |
29 |
Correct |
9158 ms |
24400 KB |
Output is correct |
30 |
Correct |
8496 ms |
24288 KB |
Output is correct |
31 |
Correct |
7947 ms |
30488 KB |
Output is correct |
32 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
901 ms |
792 KB |
Output is correct |
2 |
Correct |
464 ms |
784 KB |
Output is correct |
3 |
Correct |
921 ms |
796 KB |
Output is correct |
4 |
Correct |
898 ms |
796 KB |
Output is correct |
5 |
Correct |
891 ms |
788 KB |
Output is correct |
6 |
Correct |
18 ms |
16632 KB |
Output is correct |
7 |
Correct |
17 ms |
16888 KB |
Output is correct |
8 |
Correct |
18 ms |
16760 KB |
Output is correct |
9 |
Correct |
56 ms |
18132 KB |
Output is correct |
10 |
Correct |
14 ms |
12664 KB |
Output is correct |
11 |
Correct |
14 ms |
12756 KB |
Output is correct |
12 |
Correct |
87 ms |
15608 KB |
Output is correct |
13 |
Correct |
14 ms |
12664 KB |
Output is correct |
14 |
Correct |
14 ms |
12792 KB |
Output is correct |
15 |
Correct |
1767 ms |
42348 KB |
Output is correct |
16 |
Execution timed out |
20069 ms |
41564 KB |
Time limit exceeded |
17 |
Halted |
0 ms |
0 KB |
- |