Submission #117182

# Submission time Handle Problem Language Result Execution time Memory
117182 2019-06-15T08:21:43 Z 임유진(#2871) Treasure Hunt (CEOI11_tre) C++14
0 / 100
1087 ms 78732 KB
#include<stdio.h>

#define MAXN 400010

int n;
int num[MAXN], dep[MAXN], pidx[MAXN][20], pnum[MAXN][20], pdep[MAXN][20];

int bsnum(int x){
	int s=0, e=n-1;
	while(s<e){
		int m=(s+e)/2;
		if(x<=num[m]) e=m;
		else s=m+1;
	}
	return s;
}

int bsdep(int d, int idx){
	for(int i=19; i>=0; i--)
		if(pdep[idx][i]>=d) idx=pidx[idx][i];
	return idx;
}

void init(){
	n=1;
	num[0]=1;
	dep[0]=0;
	for(int i=0; i<20; i++){
		pidx[0][i]=pdep[0][i]=0;
		pnum[0][i]=1;
	}
}

void path(int a, int s){
	num[n]=num[n-1]+s;
	pidx[n][0]=bsnum(a);
	pdep[n][0]=dep[pidx[n][0]]-num[pidx[n][0]]+a;
	pnum[n][0]=a;
	dep[n]=pdep[n][0]+s;
	for(int i=1; i<20; i++){
		pidx[n][i]=pidx[pidx[n][i-1]][i-1];
		pdep[n][i]=pdep[pidx[n][i-1]][i-1];
		pnum[n][i]=pnum[pidx[n][i-1]][i-1];
	}
	n++;

	/*
	for(int i=0; i<n; i++){
		printf("%d %d [", num[i], dep[i]);
		for(int j=0; j<5; j++) printf("%d ", pidx[i][j]);
		printf("] [");
		for(int j=0; j<5; j++) printf("%d ", pdep[i][j]);
		printf("]\n");
	}
	*/
}

int dig(int a, int b){
	bool c=false;
	if(a>b){
		int t=a;
		a=b;
		b=t;
		c=true;
	}

	int aidx=bsnum(a), bidx=bsnum(b);
	if(aidx==bidx) return c?(a+b+1)/2:(a+b)/2;
	int adep=dep[aidx]-num[aidx]+a, bdep=dep[bidx]-num[bidx]+b;
	if(bsdep(adep, bidx)==aidx){
		int d=c?(adep+bdep+1)/2:(adep+bdep)/2;
		int idx=bsdep(d, b);
		return num[idx]-dep[idx]+d;
	}
	//printf("[%d %d %d %d]\n", aidx, bidx, adep, bdep);
	int btidx=bidx;
	for(int i=19; i>=0; i--){
		//printf("{%d %d}\n", bsdep(pdep[btidx][i], aidx), pidx[btidx][i]);
		if(bsdep(pdep[btidx][i], aidx)!=pidx[btidx][i]){
			btidx=pidx[btidx][i];
		}
		//printf("(%d)\n", btidx);
	}
	if(adep<bdep){
		int k=c?(bdep-adep+1)/2:(bdep-adep)/2;
		if(k==0){
			//printf("*");
			return pnum[btidx][0];
		}
		else return num[btidx]-dep[btidx]+pdep[btidx][0]+k;
	}
	else{
		int atidx=bsdep(pdep[btidx][0], aidx);
		return num[atidx]-dep[atidx]+pdep[btidx][0]+(c?(adep-bdep)/2:(bdep-adep+1)/2);
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 376 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 585 ms 78732 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 461 ms 11380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 723 ms 51088 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 8 ms 632 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 10 ms 888 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1087 ms 50856 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 1032 ms 50908 KB Output isn't correct