답안 #141160

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
141160 2019-08-07T04:45:38 Z babo 비밀 (JOI14_secret) C++14
0 / 100
607 ms 8752 KB
//#include "secret.h"
#include <bits/stdc++.h>

void Init(int N, int A[]);
int Query(int L, int R);

int Secret(int X, int Y);

int tr[10][2020];
int a[2020];
int n;

void bin(int now,int s,int e){
	int i,sum;
	int mid=(s+e)/2;
	for(i=mid,sum=a[mid];i<e;i++)
	{
		tr[now][i]=sum;
		if(i+1<e)
			sum=Secret(sum,a[i+1]);
	}
	for(i=mid-1,sum=a[mid-1];i>=s;i--)
	{
		tr[now][i]=sum;
		if(i-1>=s)
			sum=Secret(a[i-1],sum);
	}

	if(e<=s+2)
		return;
	bin(now+1,s,mid);
	bin(now+1,mid,e);
}

void Init(int N,int A[]){
	n=N;
	for(int i=0;i<n;i++)
		a[i]=A[i];
	bin(1,0,n);
	/*for(int i=1;i<=9;i++)
	{
		for(int j=0;j<N;j++)
		{
			printf("%d ",tr[i][j]);
		}
		puts("");
	}*/

}

int bin2(int now,int s,int e,int l,int r){
	int mid=(s+e)/2;
	if(s>r||e<l) return -1;
	if(l<=mid&&r>=mid)
	{
		if(l==mid) return tr[now][r-1];
		if(r==mid) return tr[now][l];
		return Secret(tr[now][l],tr[now][r-1]);
	}
	int temp1=bin2(now+1,s,mid,l,r);
	int temp2=bin2(now+1,mid,e,l,r);
	//printf("%d %d %d %d %d: %d\n",now,s,e,l,r,temp1==-1?temp2:temp1);
	if(temp1==-1) return temp2;
	return temp1;
}


int Query(int l,int r){
	return bin2(1,0,n,l,r+1);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 171 ms 2432 KB Output is correct - number of calls to Secret by Init = 3578, maximum number of calls to Secret by Query = 1
2 Correct 171 ms 2460 KB Output is correct - number of calls to Secret by Init = 3586, maximum number of calls to Secret by Query = 1
3 Correct 171 ms 2532 KB Output is correct - number of calls to Secret by Init = 3595, maximum number of calls to Secret by Query = 1
4 Runtime error 603 ms 8724 KB Execution killed with signal 11 (could be triggered by violating memory limits)
5 Runtime error 606 ms 8732 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 602 ms 8648 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 605 ms 8736 KB Execution killed with signal 11 (could be triggered by violating memory limits)
8 Runtime error 606 ms 8752 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 606 ms 8728 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 607 ms 8648 KB Execution killed with signal 11 (could be triggered by violating memory limits)