// And you curse yourself for things you never done
#include<bits/stdc++.h>
#include "wombats.h"
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 5010, maxm = 210, SQ = 20, MAX = 4 * (maxn / SQ +1) , mod = 1e9 + 7, inf = 1e9 + 10;
int n, m;
int tmp[maxm][maxm], opt[maxm][maxm];
void knuth(int a[maxm][maxm], int b[maxm][maxm], int ans[maxm][maxm]){
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++)
tmp[i][j] = inf;
}
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++){
int x = a[i][j] + b[j][i];
if(x < tmp[i][i])
opt[i][i] = j, tmp[i][i] = x;
}
}
for(int ln = 1; ln < m; ln++){
for(int i = 0; i+ln < m; i++){
int j = i + ln;
for(int k = opt[i][j-1]; k <= opt[i+1][j]; k++){
int x = a[i][k] + b[k][j];
if(x < tmp[i][j])
opt[i][j] = k, tmp[i][j] = x;
}
}
}
for(int ln = 1; ln < m; ln++){
for(int i = ln; i < m; i++){
int j = i - ln;
for(int k = opt[i-1][j]; k <= opt[i][j+1]; k++){
int x = a[i][k] + b[k][j];
if(x < tmp[i][j])
opt[i][j] = k, tmp[i][j] = x;
}
}
}
for(int i = 0; i < m; i++){
for(int j = 0; j < m; j++)
ans[i][j] = tmp[i][j];
}
}
int cx[maxn][maxm], cy[maxn][maxm];
int ds[MAX][maxm][maxm];
int tmp2[maxm][maxm];
void restart(int l, int r, int ans[maxm][maxm]){
for(int a = 0; a < m; a++){
ans[a][a] = 0;
for(int b = a+1; b < m; b++)
ans[a][b] = ans[a][b-1] + cy[l][b-1];
for(int b = a-1; b >= 0; b--)
ans[a][b] = ans[a][b+1] + cy[l][b];
}
for(int w = l+1; w <= r; w++){
for(int a = 0; a < m; a++){
tmp2[a][a] = cx[w-1][a];
for(int b = a+1; b < m; b++)
tmp2[a][b] = tmp2[a][b-1] + cy[w][b-1];
for(int b = a-1; b >= 0; b--)
tmp2[a][b] = tmp2[a][b+1] + cy[w][b];
}
knuth(ans, tmp2, ans);
}
}
void build(int l = 0, int r = n, int id = 1){
assert(id < MAX);
if(r-l <= SQ){
restart(l, r, ds[id]);
return;
}
int mid = (l+r) >> 1;
build(l, mid, 2*id);
build(mid, r, 2*id+1);
knuth(ds[2*id], ds[2*id+1], ds[id]);
}
void change(int pos, int l = 0, int r = n, int id = 1){
if(r < pos || pos < l)
return;
if(r-l <= SQ){
restart(l, r, ds[id]);
return;
}
int mid = (l+r) >> 1;
change(pos, l, mid, 2*id);
change(pos, mid, r, 2*id+1);
knuth(ds[2*id], ds[2*id+1], ds[id]);
}
void init(int n, int m, int H[5000][200], int V[5000][200]){
--n;
::n = n, ::m = m;
for(int i = 0; i <= n; i++){
for(int j = 0; j < m; j++)
cy[i][j] = H[i][j], cx[i][j] = V[i][j];
}
build();
}
void changeH(int P, int Q, int W) {// Y
cy[P][Q] = W;
change(P);
}
void changeV(int P, int Q, int W){ // X
cx[P][Q] = W;
change(P);
}
int escape(int V1, int V2){
return ds[1][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 |
10 ms |
14720 KB |
Output is correct |
2 |
Correct |
11 ms |
14720 KB |
Output is correct |
3 |
Correct |
93 ms |
16248 KB |
Output is correct |
4 |
Correct |
10 ms |
14720 KB |
Output is correct |
5 |
Correct |
10 ms |
14720 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
512 KB |
Output is correct |
5 |
Correct |
1 ms |
512 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
512 KB |
Output is correct |
11 |
Correct |
84 ms |
1528 KB |
Output is correct |
12 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
212 ms |
2424 KB |
Output is correct |
2 |
Correct |
158 ms |
2176 KB |
Output is correct |
3 |
Correct |
222 ms |
2168 KB |
Output is correct |
4 |
Correct |
220 ms |
2424 KB |
Output is correct |
5 |
Correct |
219 ms |
2176 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
763 ms |
2296 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
19072 KB |
Output is correct |
2 |
Correct |
13 ms |
19072 KB |
Output is correct |
3 |
Correct |
14 ms |
19072 KB |
Output is correct |
4 |
Correct |
55 ms |
20088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
215 ms |
2304 KB |
Output is correct |
2 |
Correct |
162 ms |
2304 KB |
Output is correct |
3 |
Correct |
220 ms |
2176 KB |
Output is correct |
4 |
Correct |
213 ms |
2296 KB |
Output is correct |
5 |
Correct |
214 ms |
2168 KB |
Output is correct |
6 |
Correct |
13 ms |
19072 KB |
Output is correct |
7 |
Correct |
13 ms |
19072 KB |
Output is correct |
8 |
Correct |
13 ms |
19072 KB |
Output is correct |
9 |
Correct |
54 ms |
19832 KB |
Output is correct |
10 |
Correct |
12 ms |
14720 KB |
Output is correct |
11 |
Correct |
10 ms |
14720 KB |
Output is correct |
12 |
Correct |
93 ms |
16248 KB |
Output is correct |
13 |
Correct |
10 ms |
14720 KB |
Output is correct |
14 |
Correct |
9 ms |
14720 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
488 KB |
Output is correct |
25 |
Correct |
83 ms |
1540 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
758 ms |
2272 KB |
Output is correct |
28 |
Correct |
1991 ms |
61152 KB |
Output is correct |
29 |
Correct |
2193 ms |
58232 KB |
Output is correct |
30 |
Correct |
2177 ms |
58360 KB |
Output is correct |
31 |
Correct |
2020 ms |
62072 KB |
Output is correct |
32 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
219 ms |
2260 KB |
Output is correct |
2 |
Correct |
154 ms |
2176 KB |
Output is correct |
3 |
Correct |
223 ms |
2176 KB |
Output is correct |
4 |
Correct |
220 ms |
2296 KB |
Output is correct |
5 |
Correct |
216 ms |
2176 KB |
Output is correct |
6 |
Correct |
13 ms |
19072 KB |
Output is correct |
7 |
Correct |
13 ms |
19072 KB |
Output is correct |
8 |
Correct |
16 ms |
19072 KB |
Output is correct |
9 |
Correct |
54 ms |
19960 KB |
Output is correct |
10 |
Correct |
10 ms |
14720 KB |
Output is correct |
11 |
Correct |
10 ms |
14720 KB |
Output is correct |
12 |
Correct |
89 ms |
16248 KB |
Output is correct |
13 |
Correct |
10 ms |
14720 KB |
Output is correct |
14 |
Correct |
10 ms |
14720 KB |
Output is correct |
15 |
Correct |
2552 ms |
102984 KB |
Output is correct |
16 |
Correct |
9610 ms |
104868 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
512 KB |
Output is correct |
26 |
Correct |
1 ms |
512 KB |
Output is correct |
27 |
Correct |
86 ms |
2808 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
783 ms |
2304 KB |
Output is correct |
30 |
Correct |
1947 ms |
64760 KB |
Output is correct |
31 |
Correct |
7840 ms |
111312 KB |
Output is correct |
32 |
Correct |
7818 ms |
111596 KB |
Output is correct |
33 |
Correct |
2217 ms |
62072 KB |
Output is correct |
34 |
Correct |
8330 ms |
108032 KB |
Output is correct |
35 |
Correct |
2168 ms |
61576 KB |
Output is correct |
36 |
Correct |
8271 ms |
108140 KB |
Output is correct |
37 |
Correct |
2087 ms |
66552 KB |
Output is correct |
38 |
Correct |
8138 ms |
112260 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
8376 ms |
108008 KB |
Output is correct |