답안 #64534

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
64534 2018-08-04T20:08:42 Z TadijaSebez 웜뱃 (IOI13_wombats) C++11
100 / 100
6521 ms 228552 KB
#include "wombats.h"
#include <stdio.h>
const int N=5050;
const int M=2048;
const int H=205;
const int inf=1e9+7;
int min(int a, int b){ return a>b?b:a;}
int max(int a, int b){ return a>b?a:b;}
int n,m,dp[M][H][H],ls[M],rs[M],x[N][M],y[N][M],tsz,root,opt[H];
void Take(int c)
{
	int i,j,k,l,r;
	for(i=0;i<m;i++) opt[i]=0;
	for(i=0;i<m;i++) for(j=0;j<m;j++) dp[c][i][j]=inf;
	for(i=m-1;i>-m;i--)
	{
		for(j=min(m-1,m-i-1);j+min(i,0)>=0;j--)
		{
			if(j==max(-i,0)) l=0;
			else l=opt[j-1];
			if(j==min(m-1,m-i-1)) r=m-1;
			else r=opt[j];
			for(k=l;k<=r;k++)
			{
				if(dp[c][j][j+i]>dp[ls[c]][j][k]+dp[rs[c]][k][j+i])
				{
					dp[c][j][j+i]=dp[ls[c]][j][k]+dp[rs[c]][k][j+i];
					opt[j]=k;
				}
			}
		}
	}
}
void Make(int c, int ss, int se)
{
	int i,j,k;
	for(i=0;i<m;i++) for(j=0;j<m;j++) dp[c][i][j]=inf;
	for(i=0;i<m;i++) dp[c][i][i]=0;
	for(k=ss;k<=se;k++)
	{
		for(i=0;i<m;i++)
		{
			for(j=1;j<m;j++) dp[c][i][j]=min(dp[c][i][j],dp[c][i][j-1]+x[k][j-1]);
			for(j=m-2;~j;j--) dp[c][i][j]=min(dp[c][i][j],dp[c][i][j+1]+x[k][j]);
		}
		for(i=0;i<m;i++) for(j=0;j<m;j++) dp[c][i][j]+=y[k][j];
	}
}
void Build(int &c, int ss, int se)
{
	c=++tsz;
	if(se-ss+1<=10)
	{
		Make(c,ss,se);
		return;
	}
	int mid=ss+se>>1;
	Build(ls[c],ss,mid);
	Build(rs[c],mid+1,se);
	Take(c);
}
void Upd(int c, int ss, int se, int qi)
{
	if(se-ss+1<=10)
	{
		Make(c,ss,se);
		return;
	}
	int mid=ss+se>>1;
	if(qi<=mid) Upd(ls[c],ss,mid,qi);
	else Upd(rs[c],mid+1,se,qi);
	Take(c);
}
void init(int R, int C, int H[5000][200], int V[5000][200])
{
	n=R;m=C;
	int i,j;
	for(i=0;i<n;i++) for(j=0;j<m-1;j++) x[i][j]=H[i][j];
	for(i=0;i<n-1;i++) for(j=0;j<m;j++) y[i][j]=V[i][j];
	Build(root,0,n-1);
}
void changeH(int p, int q, int w){ x[p][q]=w;Upd(root,0,n-1,p);}
void changeV(int p, int q, int w){ y[p][q]=w;Upd(root,0,n-1,p);}
int escape(int a, int b){ return dp[root][a][b];}
//------------------//
/*
int _V[5000][200],_H[5000][200];
int main()
{
	int R,C,i,j,Q,p,q,w,a,b,t;
	scanf("%i %i",&R,&C);
	for(i=0;i<R;i++) for(j=0;j<C-1;j++) scanf("%i",&_H[i][j]);
	for(i=0;i<R-1;i++) for(j=0;j<C;j++) scanf("%i",&_V[i][j]);
	init(R,C,_H,_V);
	scanf("%i",&Q);
	while(Q--)
	{
		scanf("%i",&t);
		if(t==1)
		{
			scanf("%i %i %i",&p,&q,&w);
			changeH(p,q,w);
		}
		if(t==2)
		{
			scanf("%i %i %i",&p,&q,&w);
			changeV(p,q,w);
		}
		if(t==3)
		{
			scanf("%i %i",&a,&b);
			printf("%i\n",escape(a,b));
		}
	}
	return 0;
}
*/
//------------------//

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 Build(int&, int, int)':
wombats.cpp:57:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
wombats.cpp: In function 'void Upd(int, int, int, int)':
wombats.cpp:69:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid=ss+se>>1;
          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 28664 KB Output is correct
2 Correct 26 ms 28792 KB Output is correct
3 Correct 110 ms 31336 KB Output is correct
4 Correct 26 ms 31336 KB Output is correct
5 Correct 20 ms 31336 KB Output is correct
6 Correct 2 ms 31336 KB Output is correct
7 Correct 2 ms 31336 KB Output is correct
8 Correct 3 ms 31336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 31336 KB Output is correct
2 Correct 3 ms 31336 KB Output is correct
3 Correct 3 ms 31336 KB Output is correct
4 Correct 2 ms 31336 KB Output is correct
5 Correct 3 ms 31336 KB Output is correct
6 Correct 2 ms 31336 KB Output is correct
7 Correct 2 ms 31336 KB Output is correct
8 Correct 2 ms 31336 KB Output is correct
9 Correct 4 ms 31336 KB Output is correct
10 Correct 3 ms 31336 KB Output is correct
11 Correct 79 ms 31336 KB Output is correct
12 Correct 3 ms 31336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 31336 KB Output is correct
2 Correct 108 ms 31336 KB Output is correct
3 Correct 159 ms 31336 KB Output is correct
4 Correct 124 ms 31336 KB Output is correct
5 Correct 136 ms 31336 KB Output is correct
6 Correct 2 ms 31336 KB Output is correct
7 Correct 2 ms 31336 KB Output is correct
8 Correct 3 ms 31336 KB Output is correct
9 Correct 531 ms 31336 KB Output is correct
10 Correct 3 ms 31336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 51 ms 54648 KB Output is correct
2 Correct 50 ms 54792 KB Output is correct
3 Correct 51 ms 54792 KB Output is correct
4 Correct 96 ms 55488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 128 ms 55488 KB Output is correct
2 Correct 120 ms 55488 KB Output is correct
3 Correct 132 ms 55488 KB Output is correct
4 Correct 125 ms 55488 KB Output is correct
5 Correct 125 ms 55488 KB Output is correct
6 Correct 52 ms 55488 KB Output is correct
7 Correct 47 ms 55488 KB Output is correct
8 Correct 45 ms 55488 KB Output is correct
9 Correct 93 ms 55516 KB Output is correct
10 Correct 26 ms 55516 KB Output is correct
11 Correct 28 ms 55516 KB Output is correct
12 Correct 105 ms 55516 KB Output is correct
13 Correct 26 ms 55516 KB Output is correct
14 Correct 22 ms 55516 KB Output is correct
15 Correct 2 ms 55516 KB Output is correct
16 Correct 2 ms 55516 KB Output is correct
17 Correct 2 ms 55516 KB Output is correct
18 Correct 3 ms 55516 KB Output is correct
19 Correct 3 ms 55516 KB Output is correct
20 Correct 3 ms 55516 KB Output is correct
21 Correct 2 ms 55516 KB Output is correct
22 Correct 2 ms 55516 KB Output is correct
23 Correct 4 ms 55516 KB Output is correct
24 Correct 3 ms 55516 KB Output is correct
25 Correct 81 ms 55516 KB Output is correct
26 Correct 4 ms 55516 KB Output is correct
27 Correct 505 ms 55516 KB Output is correct
28 Correct 1583 ms 135864 KB Output is correct
29 Correct 1647 ms 135864 KB Output is correct
30 Correct 1565 ms 135864 KB Output is correct
31 Correct 1649 ms 136920 KB Output is correct
32 Correct 3 ms 136920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 136920 KB Output is correct
2 Correct 128 ms 136920 KB Output is correct
3 Correct 148 ms 136920 KB Output is correct
4 Correct 146 ms 136920 KB Output is correct
5 Correct 122 ms 136920 KB Output is correct
6 Correct 45 ms 136920 KB Output is correct
7 Correct 41 ms 136920 KB Output is correct
8 Correct 39 ms 136920 KB Output is correct
9 Correct 99 ms 136920 KB Output is correct
10 Correct 23 ms 136920 KB Output is correct
11 Correct 22 ms 136920 KB Output is correct
12 Correct 100 ms 136920 KB Output is correct
13 Correct 30 ms 136920 KB Output is correct
14 Correct 22 ms 136920 KB Output is correct
15 Correct 2369 ms 217880 KB Output is correct
16 Correct 6521 ms 219448 KB Output is correct
17 Correct 2 ms 219448 KB Output is correct
18 Correct 2 ms 219448 KB Output is correct
19 Correct 2 ms 219448 KB Output is correct
20 Correct 2 ms 219448 KB Output is correct
21 Correct 2 ms 219448 KB Output is correct
22 Correct 2 ms 219448 KB Output is correct
23 Correct 3 ms 219448 KB Output is correct
24 Correct 3 ms 219448 KB Output is correct
25 Correct 3 ms 219448 KB Output is correct
26 Correct 4 ms 219448 KB Output is correct
27 Correct 90 ms 219448 KB Output is correct
28 Correct 3 ms 219448 KB Output is correct
29 Correct 593 ms 219448 KB Output is correct
30 Correct 1617 ms 219448 KB Output is correct
31 Correct 6517 ms 227716 KB Output is correct
32 Correct 6279 ms 227844 KB Output is correct
33 Correct 1550 ms 227844 KB Output is correct
34 Correct 5732 ms 227844 KB Output is correct
35 Correct 1573 ms 227844 KB Output is correct
36 Correct 5944 ms 227844 KB Output is correct
37 Correct 1736 ms 227844 KB Output is correct
38 Correct 5967 ms 228552 KB Output is correct
39 Correct 2 ms 228552 KB Output is correct
40 Correct 5965 ms 228552 KB Output is correct