#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXR = 5000;
const int MAXC = 200;
const int INF = 987654321;
int R, C, H[MAXR+10][MAXC+10], V[MAXR+10][MAXC+10];
struct Node
{
vector<vector<int>> V;
Node() { V=vector<vector<int>>(C, vector<int>(C)); }
};
Node tree[MAXR*4+10];
int opt[MAXC+10][MAXC+10];
void add(Node &now, Node &lc, Node &rc, int pos)
{
int i, j, k, p;
now=Node();
for(k=-(C-1); k<=(C-1); k++)
{
for(i=max(0, k); i<min(C+k, C); i++)
{
j=i-k; int l, r;
if(i==0) l=0;
else l=opt[i-1][j];
if(j==C-1) r=C-1;
else r=opt[i][j+1];
int t=l; now.V[i][j]=INF;
for(p=l; p<=r; p++)
{
if(now.V[i][j]>lc.V[i][p]+rc.V[p][j]+V[pos][p])
{
t=p; now.V[i][j]=lc.V[i][p]+rc.V[p][j]+V[pos][p];
}
}
opt[i][j]=t;
}
}
}
void init(int node, int tl, int tr)
{
if(tl==tr)
{
int i, j;
tree[node]=Node();
for(i=0; i<C; i++)
{
int s=0;
for(j=i+1; j<C; j++)
{
s+=H[tl][j-1];
tree[node].V[i][j]=tree[node].V[j][i]=s;
}
}
return;
}
int mid=tl+tr>>1;
init(node*2, tl, mid);
init(node*2+1, mid+1, tr);
add(tree[node], tree[node*2], tree[node*2+1], mid);
}
void init(int _R, int _C, int _H[5000][200], int _V[5000][200])
{
int i, j;
R=_R; C=_C;
for(i=0; i<R; i++) for(j=0; j+1<C; j++) H[i][j]=_H[i][j];
for(i=0; i+1<R; i++) for(j=0; j<C; j++) V[i][j]=_V[i][j];
init(1, 0, R-1);
}
void updateH(int node, int tl, int tr, int y)
{
if(tl==tr)
{
int i, j;
for(i=0; i<C; i++)
{
int s=0;
for(j=i+1; j<C; j++)
{
s+=H[tl][j-1];
tree[node].V[i][j]=tree[node].V[j][i]=s;
}
}
return;
}
int mid=tl+tr>>1;
if(y<=mid) updateH(node*2, tl, mid, y);
else updateH(node*2+1, mid+1, tr, y);
add(tree[node], tree[node*2], tree[node*2+1], mid);
}
void updateV(int node, int tl, int tr, int y)
{
int mid=tl+tr>>1;
if(y==mid) { add(tree[node], tree[node*2], tree[node*2+1], mid); return; }
if(y<=mid) updateV(node*2, tl, mid, y);
else updateV(node*2+1, mid+1, tr, y);
add(tree[node], tree[node*2], tree[node*2+1], mid);
}
void changeH(int P, int Q, int W)
{
H[P][Q]=W;
updateH(1, 0, R-1, P);
}
void changeV(int P, int Q, int W)
{
V[P][Q]=W;
updateV(1, 0, R-1, P);
}
int escape(int V1, int V2)
{
return tree[1].V[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;
^~~
wombats.cpp: In function 'void init(int, int, int)':
wombats.cpp:70:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
wombats.cpp: In function 'void updateH(int, int, int, int)':
wombats.cpp:102:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
wombats.cpp: In function 'void updateV(int, int, int, int)':
wombats.cpp:110:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
int mid=tl+tr>>1;
~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
9464 KB |
Output is correct |
2 |
Correct |
12 ms |
9464 KB |
Output is correct |
3 |
Correct |
108 ms |
11000 KB |
Output is correct |
4 |
Correct |
14 ms |
9464 KB |
Output is correct |
5 |
Correct |
15 ms |
9464 KB |
Output is correct |
6 |
Correct |
5 ms |
760 KB |
Output is correct |
7 |
Correct |
5 ms |
760 KB |
Output is correct |
8 |
Correct |
5 ms |
756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
760 KB |
Output is correct |
2 |
Correct |
5 ms |
760 KB |
Output is correct |
3 |
Correct |
6 ms |
760 KB |
Output is correct |
4 |
Correct |
6 ms |
1016 KB |
Output is correct |
5 |
Correct |
6 ms |
1016 KB |
Output is correct |
6 |
Correct |
6 ms |
1016 KB |
Output is correct |
7 |
Correct |
6 ms |
1016 KB |
Output is correct |
8 |
Correct |
6 ms |
1016 KB |
Output is correct |
9 |
Correct |
6 ms |
1016 KB |
Output is correct |
10 |
Correct |
6 ms |
1016 KB |
Output is correct |
11 |
Correct |
95 ms |
2016 KB |
Output is correct |
12 |
Correct |
6 ms |
1016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
124 ms |
9848 KB |
Output is correct |
2 |
Correct |
91 ms |
9592 KB |
Output is correct |
3 |
Correct |
128 ms |
9852 KB |
Output is correct |
4 |
Correct |
116 ms |
9848 KB |
Output is correct |
5 |
Correct |
124 ms |
9720 KB |
Output is correct |
6 |
Correct |
6 ms |
888 KB |
Output is correct |
7 |
Correct |
5 ms |
760 KB |
Output is correct |
8 |
Correct |
5 ms |
760 KB |
Output is correct |
9 |
Correct |
429 ms |
9892 KB |
Output is correct |
10 |
Correct |
5 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
18040 KB |
Output is correct |
2 |
Correct |
20 ms |
18040 KB |
Output is correct |
3 |
Correct |
20 ms |
18040 KB |
Output is correct |
4 |
Correct |
68 ms |
18936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
127 ms |
9720 KB |
Output is correct |
2 |
Correct |
90 ms |
9592 KB |
Output is correct |
3 |
Correct |
136 ms |
9848 KB |
Output is correct |
4 |
Correct |
117 ms |
9852 KB |
Output is correct |
5 |
Correct |
118 ms |
9720 KB |
Output is correct |
6 |
Correct |
20 ms |
18040 KB |
Output is correct |
7 |
Correct |
20 ms |
18040 KB |
Output is correct |
8 |
Correct |
24 ms |
18144 KB |
Output is correct |
9 |
Correct |
65 ms |
18936 KB |
Output is correct |
10 |
Correct |
15 ms |
9464 KB |
Output is correct |
11 |
Correct |
12 ms |
9464 KB |
Output is correct |
12 |
Correct |
102 ms |
11232 KB |
Output is correct |
13 |
Correct |
14 ms |
9468 KB |
Output is correct |
14 |
Correct |
14 ms |
9464 KB |
Output is correct |
15 |
Correct |
5 ms |
760 KB |
Output is correct |
16 |
Correct |
5 ms |
760 KB |
Output is correct |
17 |
Correct |
5 ms |
760 KB |
Output is correct |
18 |
Correct |
6 ms |
1016 KB |
Output is correct |
19 |
Correct |
6 ms |
1016 KB |
Output is correct |
20 |
Correct |
6 ms |
1016 KB |
Output is correct |
21 |
Correct |
6 ms |
1016 KB |
Output is correct |
22 |
Correct |
6 ms |
1016 KB |
Output is correct |
23 |
Correct |
6 ms |
1016 KB |
Output is correct |
24 |
Correct |
6 ms |
1016 KB |
Output is correct |
25 |
Correct |
95 ms |
2040 KB |
Output is correct |
26 |
Correct |
6 ms |
1016 KB |
Output is correct |
27 |
Correct |
406 ms |
9952 KB |
Output is correct |
28 |
Runtime error |
2708 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
9720 KB |
Output is correct |
2 |
Correct |
90 ms |
9592 KB |
Output is correct |
3 |
Correct |
145 ms |
9976 KB |
Output is correct |
4 |
Correct |
116 ms |
9976 KB |
Output is correct |
5 |
Correct |
125 ms |
9848 KB |
Output is correct |
6 |
Correct |
21 ms |
18040 KB |
Output is correct |
7 |
Correct |
22 ms |
18040 KB |
Output is correct |
8 |
Correct |
20 ms |
18040 KB |
Output is correct |
9 |
Correct |
66 ms |
18936 KB |
Output is correct |
10 |
Correct |
15 ms |
9464 KB |
Output is correct |
11 |
Correct |
14 ms |
9464 KB |
Output is correct |
12 |
Correct |
102 ms |
11040 KB |
Output is correct |
13 |
Correct |
14 ms |
9464 KB |
Output is correct |
14 |
Correct |
13 ms |
9592 KB |
Output is correct |
15 |
Runtime error |
1075 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
16 |
Halted |
0 ms |
0 KB |
- |