#include "wombats.h"
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000001
#define B 10
struct node{
int n,d[200][200];
void ini(int x){
n=x;
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
if(i==j)d[i][j]=0;
else d[i][j]=INF;
}
}
}
node plus(node &q){
node res;
res.ini(n);
int a[405][205],s;
for(int i=n-1;i>-n;i--){
int *b=a[i+n+1],*c=a[i+n];
for(int j=max(-i,0);i+j<n&&j<n;j++){
s=INF;
int x,y,z=i+j,*e=d[z];
if(j-1>=0)x=b[j-1];
else x=0;
if(z+1<n)y=b[j];
else y=n-1;
for(int k=x;k<=y;k++){
if(e[k]+q.d[k][j]<s){
x=k;
s=e[k]+q.d[k][j];
}
}
c[j]=x;
res.d[z][j]=min(s,INF);
}
}
return res;
}
};
struct SEG{
int n;
node seg[1<<10];
void ini(int x){
n=x;
for(int i=0;i<1<<10;i++)seg[i].ini(n);
}
void up(int a,node &q){
a+=(1<<9)-1;
seg[a]=q;
while(a>0){
a=(a-1)/2;
seg[a]=seg[a*2+1].plus(seg[a*2+2]);
}
}
};
int h[5005][205],w[5005][205],n,m,p[B][205];
SEG s;
node res[B];
void change(int x){
x=x/B;
for(int i=0;i<B&&x*B+i<n;i++)p[i][0]=0,res[i].ini(m);
for(int i=0;i<B&&x*B+i<n;i++)for(int j=1;j<m;j++)p[i][j]=p[i][j-1]+h[x*B+i][j-1];
for(int i=0;i<B&&x*B+i<n;i++){
for(int j=0;j<m;j++){
for(int k=0;k<m;k++){
res[i].d[j][k]=p[i][max(j,k)]-p[i][min(j,k)]+w[x*B+i][k];
}
}
}
for(int i=1;i<B&&x*B+i<n;i++)res[0]=res[0].plus(res[i]);
s.up(x,res[0]);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
n=R,m=C;
s.ini(m);
for(int i=0;i<n;i++)for(int j=0;j<m-1;j++)h[i][j]=H[i][j];
for(int i=0;i<n-1;i++)for(int j=0;j<m;j++)w[i][j]=V[i][j];
for(int i=0;i<n;i++)change(i);
}
void changeH(int a, int b, int x) {
h[a][b]=x;
change(a);
}
void changeV(int a, int b, int x) {
w[a][b]=x;
change(a);
}
int escape(int a, int b) {
return s.seg[0].d[a][b];
}
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 |
1322 ms |
165352 KB |
Output is correct |
2 |
Correct |
1318 ms |
165544 KB |
Output is correct |
3 |
Correct |
1381 ms |
167040 KB |
Output is correct |
4 |
Correct |
1342 ms |
165300 KB |
Output is correct |
5 |
Correct |
1321 ms |
165496 KB |
Output is correct |
6 |
Correct |
7 ms |
6392 KB |
Output is correct |
7 |
Correct |
7 ms |
6520 KB |
Output is correct |
8 |
Correct |
7 ms |
6392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6520 KB |
Output is correct |
2 |
Correct |
7 ms |
6520 KB |
Output is correct |
3 |
Correct |
7 ms |
6392 KB |
Output is correct |
4 |
Correct |
25 ms |
22016 KB |
Output is correct |
5 |
Correct |
25 ms |
22008 KB |
Output is correct |
6 |
Correct |
25 ms |
22136 KB |
Output is correct |
7 |
Correct |
25 ms |
22008 KB |
Output is correct |
8 |
Correct |
24 ms |
21112 KB |
Output is correct |
9 |
Correct |
25 ms |
22008 KB |
Output is correct |
10 |
Correct |
24 ms |
21240 KB |
Output is correct |
11 |
Correct |
101 ms |
22904 KB |
Output is correct |
12 |
Correct |
29 ms |
22008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
588 ms |
87804 KB |
Output is correct |
2 |
Correct |
495 ms |
87160 KB |
Output is correct |
3 |
Correct |
582 ms |
87820 KB |
Output is correct |
4 |
Correct |
589 ms |
87832 KB |
Output is correct |
5 |
Correct |
584 ms |
87024 KB |
Output is correct |
6 |
Correct |
7 ms |
6392 KB |
Output is correct |
7 |
Correct |
7 ms |
6392 KB |
Output is correct |
8 |
Correct |
7 ms |
6520 KB |
Output is correct |
9 |
Correct |
1385 ms |
87856 KB |
Output is correct |
10 |
Correct |
9 ms |
8824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1350 ms |
173268 KB |
Output is correct |
2 |
Correct |
1365 ms |
173304 KB |
Output is correct |
3 |
Correct |
1355 ms |
173280 KB |
Output is correct |
4 |
Correct |
1392 ms |
174072 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
583 ms |
87848 KB |
Output is correct |
2 |
Correct |
498 ms |
87080 KB |
Output is correct |
3 |
Correct |
593 ms |
88056 KB |
Output is correct |
4 |
Correct |
589 ms |
87840 KB |
Output is correct |
5 |
Correct |
577 ms |
86992 KB |
Output is correct |
6 |
Correct |
1350 ms |
173316 KB |
Output is correct |
7 |
Correct |
1353 ms |
173288 KB |
Output is correct |
8 |
Correct |
1360 ms |
173336 KB |
Output is correct |
9 |
Correct |
1372 ms |
174108 KB |
Output is correct |
10 |
Correct |
1309 ms |
165368 KB |
Output is correct |
11 |
Correct |
1347 ms |
165340 KB |
Output is correct |
12 |
Correct |
1401 ms |
167032 KB |
Output is correct |
13 |
Correct |
1335 ms |
165380 KB |
Output is correct |
14 |
Correct |
1343 ms |
165508 KB |
Output is correct |
15 |
Correct |
7 ms |
6520 KB |
Output is correct |
16 |
Correct |
7 ms |
6392 KB |
Output is correct |
17 |
Correct |
7 ms |
6520 KB |
Output is correct |
18 |
Correct |
26 ms |
22008 KB |
Output is correct |
19 |
Correct |
25 ms |
22008 KB |
Output is correct |
20 |
Correct |
25 ms |
22008 KB |
Output is correct |
21 |
Correct |
25 ms |
22008 KB |
Output is correct |
22 |
Correct |
24 ms |
21240 KB |
Output is correct |
23 |
Correct |
25 ms |
22008 KB |
Output is correct |
24 |
Correct |
24 ms |
21240 KB |
Output is correct |
25 |
Correct |
101 ms |
23048 KB |
Output is correct |
26 |
Correct |
25 ms |
22008 KB |
Output is correct |
27 |
Correct |
1392 ms |
87672 KB |
Output is correct |
28 |
Correct |
12328 ms |
176400 KB |
Output is correct |
29 |
Correct |
11969 ms |
160236 KB |
Output is correct |
30 |
Correct |
11988 ms |
160216 KB |
Output is correct |
31 |
Correct |
12449 ms |
177548 KB |
Output is correct |
32 |
Correct |
9 ms |
8828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
593 ms |
87800 KB |
Output is correct |
2 |
Correct |
503 ms |
87032 KB |
Output is correct |
3 |
Correct |
594 ms |
87800 KB |
Output is correct |
4 |
Correct |
585 ms |
87768 KB |
Output is correct |
5 |
Correct |
587 ms |
87160 KB |
Output is correct |
6 |
Correct |
1352 ms |
173432 KB |
Output is correct |
7 |
Correct |
1346 ms |
173320 KB |
Output is correct |
8 |
Correct |
1372 ms |
173312 KB |
Output is correct |
9 |
Correct |
1372 ms |
174128 KB |
Output is correct |
10 |
Correct |
1324 ms |
165496 KB |
Output is correct |
11 |
Correct |
1331 ms |
165436 KB |
Output is correct |
12 |
Correct |
1429 ms |
167024 KB |
Output is correct |
13 |
Correct |
1335 ms |
165392 KB |
Output is correct |
14 |
Correct |
1323 ms |
165396 KB |
Output is correct |
15 |
Execution timed out |
20089 ms |
178760 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |