Submission #2472

# Submission time Handle Problem Language Result Execution time Memory
2472 2013-07-22T07:59:44 Z ainta Wombats (IOI13_wombats) C++
100 / 100
7148 ms 101884 KB
#include "wombats.h"
#define SZ 256
#define INF 999999999
int D[512][201][201],bucket_sz,h[5010][210],v[5010][210],TP[23][210][210],r,c;
void Do(int num,int a)
{
	int i,j,k,bsz=bucket_sz;
	if(a+bsz>r)bsz=r-a;

	for(i=0;i<=bsz;i++)
		for(j=0;j<c;j++)
			for(k=0;k<c;k++)
				TP[i][j][k]=INF;
	for(i=0;i<c;i++)TP[0][i][i]=0;
	for(i=0;i<bsz;i++)
	{
		for(j=0;j<c;j++){
			for(k=1;k<c;k++)
				if(TP[i][j][k]>TP[i][j][k-1]+h[a+i][k-1])
					TP[i][j][k]=TP[i][j][k-1]+h[a+i][k-1];
			for(k=c-2;k>=0;k--)
				if(TP[i][j][k]>TP[i][j][k+1]+h[a+i][k])
					TP[i][j][k]=TP[i][j][k+1]+h[a+i][k];
		}
		for(j=0;j<c;j++)
			for(k=0;k<c;k++)
				TP[i+1][j][k]=TP[i][j][k]+v[a+i][k];
	}
	for(i=0;i<c;i++)
		for(j=0;j<c;j++)
			D[num][i][j]=TP[bsz][i][j];
}
void Update(int a)
{
	int i,j,k,b,e,w[201],s,l;
	int c1=a*2,c2=a*2+1;
	for(i=0;i<c;i++)for(j=0;j<c;j++)D[a][i][j]=INF+1;
	for(i=0;i<c;i++)w[i]=0;
	w[0]=c-1;
	for(i=c-1;i>-c;i--){
		b=-i;e=c-1-i;
		if(b<0)b=0;
		if(e>=c)e=c-1;
		for(j=b;j<=e;j++){
			if(j==b)s=0;
			else s=w[j-1];
			if(j==e)l=c-1;
			else l=w[j];
			for(k=s;k<=l;k++){
				if(D[a][j][j+i]>D[c1][j][k]+D[c2][k][j+i]){
					D[a][j][j+i]=D[c1][j][k]+D[c2][k][j+i];
					w[j]=k;
				}
			}
		}
	}
}
void changeV(int P, int Q, int W)
{
	v[P][Q]=W;
	int a=P/bucket_sz;
	Do(SZ+a,a*bucket_sz);
	a+=SZ;
	while(a>1){
		a>>=1;
		Update(a);
	}
}
void changeH(int P, int Q, int W)
{
	h[P][Q]=W;
	int a=P/bucket_sz;
	Do(SZ+a,a*bucket_sz);
	a+=SZ;
	while(a>1){
		a>>=1;
		Update(a);
	}
}
int escape(int V1, int V2)
{
	return D[1][V1][V2];
}
void init(int R, int C, int H[5000][200], int V[5000][200])
{
	r=R,c=C;
	int i,j,k;
	for(i=0;i<R;i++)for(j=0;j<C-1;j++)h[i][j]=H[i][j];
	for(i=0;i<R-1;i++)for(j=0;j<C;j++)v[i][j]=V[i][j];
	bucket_sz=(R-1)/256+1;
	for(i=0;i<R;i+=bucket_sz)
	{
		Do(SZ+i/bucket_sz,i);
	}
	for(i=SZ+i/bucket_sz;i<512;i++){
		for(j=0;j<C;j++){
			for(k=0;k<C;k++)D[i][j][k]=INF;
			D[i][j][j]=0;
		}
	}
	for(i=SZ-1;i>=1;i--)Update(i);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 101884 KB Output is correct
2 Correct 0 ms 101884 KB Output is correct
3 Correct 88 ms 101884 KB Output is correct
4 Correct 0 ms 101884 KB Output is correct
5 Correct 0 ms 101884 KB Output is correct
6 Correct 0 ms 101884 KB Output is correct
7 Correct 0 ms 101884 KB Output is correct
8 Correct 0 ms 101884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 101884 KB Output is correct
2 Correct 0 ms 101884 KB Output is correct
3 Correct 0 ms 101884 KB Output is correct
4 Correct 4 ms 101884 KB Output is correct
5 Correct 0 ms 101884 KB Output is correct
6 Correct 0 ms 101884 KB Output is correct
7 Correct 0 ms 101884 KB Output is correct
8 Correct 0 ms 101884 KB Output is correct
9 Correct 0 ms 101884 KB Output is correct
10 Correct 0 ms 101884 KB Output is correct
11 Correct 88 ms 101884 KB Output is correct
12 Correct 0 ms 101884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 101884 KB Output is correct
2 Correct 164 ms 101884 KB Output is correct
3 Correct 208 ms 101884 KB Output is correct
4 Correct 200 ms 101884 KB Output is correct
5 Correct 208 ms 101884 KB Output is correct
6 Correct 0 ms 101884 KB Output is correct
7 Correct 0 ms 101884 KB Output is correct
8 Correct 0 ms 101884 KB Output is correct
9 Correct 628 ms 101884 KB Output is correct
10 Correct 0 ms 101884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 101884 KB Output is correct
2 Correct 4 ms 101884 KB Output is correct
3 Correct 4 ms 101884 KB Output is correct
4 Correct 52 ms 101884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 200 ms 101884 KB Output is correct
2 Correct 160 ms 101884 KB Output is correct
3 Correct 196 ms 101884 KB Output is correct
4 Correct 216 ms 101884 KB Output is correct
5 Correct 204 ms 101884 KB Output is correct
6 Correct 8 ms 101884 KB Output is correct
7 Correct 4 ms 101884 KB Output is correct
8 Correct 8 ms 101884 KB Output is correct
9 Correct 60 ms 101884 KB Output is correct
10 Correct 0 ms 101884 KB Output is correct
11 Correct 4 ms 101884 KB Output is correct
12 Correct 92 ms 101884 KB Output is correct
13 Correct 0 ms 101884 KB Output is correct
14 Correct 0 ms 101884 KB Output is correct
15 Correct 0 ms 101884 KB Output is correct
16 Correct 0 ms 101884 KB Output is correct
17 Correct 0 ms 101884 KB Output is correct
18 Correct 0 ms 101884 KB Output is correct
19 Correct 4 ms 101884 KB Output is correct
20 Correct 0 ms 101884 KB Output is correct
21 Correct 0 ms 101884 KB Output is correct
22 Correct 0 ms 101884 KB Output is correct
23 Correct 0 ms 101884 KB Output is correct
24 Correct 0 ms 101884 KB Output is correct
25 Correct 84 ms 101884 KB Output is correct
26 Correct 0 ms 101884 KB Output is correct
27 Correct 604 ms 101884 KB Output is correct
28 Correct 1808 ms 101884 KB Output is correct
29 Correct 1664 ms 101884 KB Output is correct
30 Correct 1748 ms 101884 KB Output is correct
31 Correct 1840 ms 101884 KB Output is correct
32 Correct 0 ms 101884 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 192 ms 101884 KB Output is correct
2 Correct 156 ms 101884 KB Output is correct
3 Correct 200 ms 101884 KB Output is correct
4 Correct 192 ms 101884 KB Output is correct
5 Correct 200 ms 101884 KB Output is correct
6 Correct 0 ms 101884 KB Output is correct
7 Correct 4 ms 101884 KB Output is correct
8 Correct 8 ms 101884 KB Output is correct
9 Correct 48 ms 101884 KB Output is correct
10 Correct 0 ms 101884 KB Output is correct
11 Correct 0 ms 101884 KB Output is correct
12 Correct 96 ms 101884 KB Output is correct
13 Correct 0 ms 101884 KB Output is correct
14 Correct 0 ms 101884 KB Output is correct
15 Correct 1416 ms 101884 KB Output is correct
16 Correct 7148 ms 101884 KB Output is correct
17 Correct 0 ms 101884 KB Output is correct
18 Correct 0 ms 101884 KB Output is correct
19 Correct 0 ms 101884 KB Output is correct
20 Correct 0 ms 101884 KB Output is correct
21 Correct 0 ms 101884 KB Output is correct
22 Correct 0 ms 101884 KB Output is correct
23 Correct 0 ms 101884 KB Output is correct
24 Correct 0 ms 101884 KB Output is correct
25 Correct 0 ms 101884 KB Output is correct
26 Correct 0 ms 101884 KB Output is correct
27 Correct 88 ms 101884 KB Output is correct
28 Correct 0 ms 101884 KB Output is correct
29 Correct 624 ms 101884 KB Output is correct
30 Correct 1812 ms 101884 KB Output is correct
31 Correct 6784 ms 101884 KB Output is correct
32 Correct 6816 ms 101884 KB Output is correct
33 Correct 1700 ms 101884 KB Output is correct
34 Correct 6296 ms 101884 KB Output is correct
35 Correct 1728 ms 101884 KB Output is correct
36 Correct 6328 ms 101884 KB Output is correct
37 Correct 1816 ms 101884 KB Output is correct
38 Correct 6872 ms 101884 KB Output is correct
39 Correct 0 ms 101884 KB Output is correct
40 Correct 6480 ms 101884 KB Output is correct