Submission #358278

# Submission time Handle Problem Language Result Execution time Memory
358278 2021-01-25T09:33:03 Z Kerim Wombats (IOI13_wombats) C++17
55 / 100
20000 ms 186004 KB
#include "wombats.h"
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;

typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int R=5005,C=202;
int h[R][C],v[R][C],n,m;
struct node{
	vector<vector<int> >dp;	
	void init(){
		dp.resize(m);
		for(int i=0;i<m;i++)
			dp[i].resize(m);
	}
	void fill(){
		init();
		for(int i=0;i<m;i++)
			for(int j=0;j<m;j++)
				dp[i][j]=INF;
	}
	void print(){
		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++)
				printf("%d ",dp[i][j]);
			puts("");
		}
	}
}seg[R<<2];
int opt[C][C];
node merge(node x,node y,int mid){
	node z;z.fill();
	for(int len=0;len<m;len++){
		for(int i=0,k;i+len<m;i++){
			k=i+len;
			if(i==k){
				for(int j=0;j<m;j++)
					if(umin(z.dp[i][k],x.dp[i][j]+v[mid][j]+y.dp[j][k]))
						opt[i][k]=j;
			}
			else{
				for(int j=opt[i][k-1];j<=opt[i+1][k];j++)
					if(umin(z.dp[i][k],x.dp[i][j]+v[mid][j]+y.dp[j][k]))
						opt[i][k]=j;
				
				for(int j=opt[k-1][i];j<=opt[k][i+1];j++)
					if(umin(z.dp[k][i],x.dp[k][j]+v[mid][j]+y.dp[j][i]))
						opt[k][i]=j;
			}	
		}
	}
	for(int i=0;i<m;i++)
		for(int j=0;j<m;j++)
			for(int k=0;k<m;k++)
				umin(z.dp[i][k],x.dp[i][j]+v[mid][j]+y.dp[j][k]);
	return z;
}	
const int L=10;
int odp[L][C];
void naive(int nd,int x,int y){
	queue<PII>q;int nx,ny,id;
	for(int i=0;i<m;i++){
		memset(odp,127,sizeof odp);
		q.push(mp(x,i));odp[0][i]=0;
		while(!q.empty()){
			nx=q.front().ff;ny=q.front().ss;q.pop();id=nx-x;
			if(ny>0 and umin(odp[id][ny-1],odp[id][ny]+h[nx][ny-1]))
				q.push(mp(nx,ny-1));		
			if(ny+1<m and umin(odp[id][ny+1],odp[id][ny]+h[nx][ny]))
				q.push(mp(nx,ny+1));
			if(nx<y and umin(odp[id+1][ny],odp[id][ny]+v[nx][ny]))
				q.push(mp(nx+1,ny));				
		}
		for(int j=0;j<m;j++)
			seg[nd].dp[i][j]=odp[y-x][j];
	}	
}
void build(int nd,int x,int y){
	seg[nd].init();
	if(y-x<L){
		naive(nd,x,y);
		return;			
	}
	int mid=(x+y)>>1;
	build(nd<<1,x,mid);
	build(nd<<1|1,mid+1,y);
	seg[nd]=merge(seg[nd<<1],seg[nd<<1|1],mid);
}
void upd(int p,int nd,int x,int y){
	if(y-x<L){
		naive(nd,x,y);	
		return;
	}
	int mid=(x+y)>>1;
	if(p<=mid)upd(p,nd<<1,x,mid);
	else upd(p,nd<<1|1,mid+1,y);
	seg[nd]=merge(seg[nd<<1],seg[nd<<1|1],mid);
}
void init(int R, int C, int H[5000][200], int V[5000][200]) {
	n=R;m=C;
	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++)
			v[i][j]=V[i][j];
	build(1,0,n-1);
}
void changeH(int P, int Q, int W) {
	h[P][Q]=W;upd(P,1,0,n-1);
}
void changeV(int P, int Q, int W) {
	v[P][Q]=W;upd(P,1,0,n-1);
}
int escape(int V1, int V2) {
    return seg[1].dp[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;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8684 KB Output is correct
2 Correct 7 ms 8684 KB Output is correct
3 Correct 84 ms 10348 KB Output is correct
4 Correct 8 ms 8684 KB Output is correct
5 Correct 7 ms 8684 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 3 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 748 KB Output is correct
2 Correct 1 ms 748 KB Output is correct
3 Correct 1 ms 748 KB Output is correct
4 Correct 1 ms 876 KB Output is correct
5 Correct 1 ms 876 KB Output is correct
6 Correct 1 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 1 ms 876 KB Output is correct
9 Correct 2 ms 876 KB Output is correct
10 Correct 1 ms 876 KB Output is correct
11 Correct 79 ms 1900 KB Output is correct
12 Correct 3 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 840 ms 2796 KB Output is correct
2 Correct 1010 ms 2796 KB Output is correct
3 Correct 807 ms 2668 KB Output is correct
4 Correct 802 ms 2924 KB Output is correct
5 Correct 766 ms 2796 KB Output is correct
6 Correct 1 ms 748 KB Output is correct
7 Correct 1 ms 748 KB Output is correct
8 Correct 1 ms 748 KB Output is correct
9 Correct 4851 ms 2924 KB Output is correct
10 Correct 1 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 16620 KB Output is correct
2 Correct 22 ms 16620 KB Output is correct
3 Correct 20 ms 16620 KB Output is correct
4 Correct 57 ms 17516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 777 ms 2796 KB Output is correct
2 Correct 1091 ms 2924 KB Output is correct
3 Correct 790 ms 2796 KB Output is correct
4 Correct 782 ms 2752 KB Output is correct
5 Correct 804 ms 2668 KB Output is correct
6 Correct 15 ms 16620 KB Output is correct
7 Correct 16 ms 16620 KB Output is correct
8 Correct 15 ms 16624 KB Output is correct
9 Correct 53 ms 17516 KB Output is correct
10 Correct 8 ms 8684 KB Output is correct
11 Correct 8 ms 8684 KB Output is correct
12 Correct 98 ms 10312 KB Output is correct
13 Correct 9 ms 8684 KB Output is correct
14 Correct 9 ms 8684 KB Output is correct
15 Correct 1 ms 748 KB Output is correct
16 Correct 1 ms 748 KB Output is correct
17 Correct 1 ms 748 KB Output is correct
18 Correct 1 ms 876 KB Output is correct
19 Correct 1 ms 876 KB Output is correct
20 Correct 1 ms 876 KB Output is correct
21 Correct 3 ms 876 KB Output is correct
22 Correct 1 ms 876 KB Output is correct
23 Correct 1 ms 876 KB Output is correct
24 Correct 1 ms 876 KB Output is correct
25 Correct 81 ms 1900 KB Output is correct
26 Correct 5 ms 876 KB Output is correct
27 Correct 4646 ms 2752 KB Output is correct
28 Correct 15607 ms 61216 KB Output is correct
29 Correct 9764 ms 58692 KB Output is correct
30 Correct 9674 ms 58732 KB Output is correct
31 Execution timed out 20032 ms 61760 KB Time limit exceeded
32 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 781 ms 2796 KB Output is correct
2 Correct 997 ms 2668 KB Output is correct
3 Correct 796 ms 2796 KB Output is correct
4 Correct 791 ms 3000 KB Output is correct
5 Correct 764 ms 2796 KB Output is correct
6 Correct 16 ms 16748 KB Output is correct
7 Correct 19 ms 16716 KB Output is correct
8 Correct 15 ms 16620 KB Output is correct
9 Correct 54 ms 17516 KB Output is correct
10 Correct 7 ms 8684 KB Output is correct
11 Correct 7 ms 8684 KB Output is correct
12 Correct 91 ms 10348 KB Output is correct
13 Correct 7 ms 8684 KB Output is correct
14 Correct 7 ms 8684 KB Output is correct
15 Correct 8912 ms 185476 KB Output is correct
16 Execution timed out 20047 ms 186004 KB Time limit exceeded
17 Halted 0 ms 0 KB -