Submission #2630

# Submission time Handle Problem Language Result Execution time Memory
2630 2013-07-28T07:24:09 Z jihoon 공장 (KOI13_factory) C++
14.77 / 20
1000 ms 16712 KB
#include<stdio.h>
int tree[500001][4]={0}; //1: left, 2: right. 3: gap 0: rightgae
int sn[1000001]={0};
int sv[500000][2]={0};
int n;
long long int p;

int tot(int here,int gap,int wichi){
	int cnt=0,pp=-1,i,prev=-1,prevn=-1;
	if(wichi>1){
		do{
	//		printf("%d",here);
			prevn=here;
			if(tree[here][3]>gap){
				cnt+=tree[here][0];
				here=tree[here][1];
				prev=1;
			}else{
				tree[here][0]++;
				here=tree[here][2];
				prev=2;
			}
		}while(here>0);
	}
	tree[wichi][3]=gap;
	tree[wichi][0]=1;
	if(prev>-1) tree[prevn][prev]=wichi;
	return cnt;
}

int main(){
    int im,i;
//    freopen("input.txt","r",stdin);
//   freopen("output.txt","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++){
        scanf("%d",&im);
        sn[im]=i;
    }
    for(i=0;i<n;i++){
        scanf("%d",&im);
//		printf("!");
        p+=tot(1,sn[im],i+1);
    }
	printf("%lld",p);
//	fclose(stdin);
//	fclose(stdout);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16712 KB Output is correct
2 Correct 0 ms 16712 KB Output is correct
3 Correct 0 ms 16712 KB Output is correct
4 Correct 0 ms 16712 KB Output is correct
5 Correct 0 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 16712 KB Output is correct
2 Correct 4 ms 16712 KB Output is correct
3 Correct 0 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1000 ms 16708 KB Program timed out
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 68 ms 16712 KB Output is correct
2 Correct 112 ms 16712 KB Output is correct
3 Correct 160 ms 16712 KB Output is correct
4 Correct 236 ms 16712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 336 ms 16712 KB Output is correct
2 Execution timed out 1000 ms 16708 KB Program timed out
3 Halted 0 ms 0 KB -