답안 #94881

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94881 2019-01-24T18:01:34 Z karlopuh Pismo (COCI18_pismo) C++14
0 / 70
5 ms 504 KB
#include <bits/stdc++.h>
using namespace std;

pair <int,int> stablo [100001];
int n;
int pot=1;
int mini = 1e9 + 10;
int pom[2];


int query(int cvor,int od,int doo,int a,int b){
	if(od<=a && doo>=b)return cvor;
	
	int rj1=-1,rj2=-1;
	if((doo+od)/2>=a){
		rj1=query(cvor*2,od,(doo+od)/2,a,b);
	}
	if((doo+od)/2+1<=b){
		rj2=query(cvor*2+1,(doo+od)/2+1,doo,a,b);
	}
	
	if(rj1==-1)return rj2;
	else if(rj2==-1) return rj1;
	else{
		pom[0]=rj1;
		pom[1]=rj2;
		return -1;
	}
}


void create(){
	for(int i=pot-1;i>=1;i--){
		stablo[i].first=min(stablo[i*2].first,stablo[i*2+1].first);
		stablo[i].second=max(stablo[i*2].second,stablo[i*2+1].second);
	}
}


int main(){
	cin>>n;
	for(;pot<n;pot*=2);
	
	for(int i=0;i<n;i++){
		cin>>stablo[pot+i].first;
		stablo[pot+i].second=stablo[pot+i].first;
	}
	
	for(int i=pot+n;i<=pot*2-1;i++){
		stablo[i].first=1e9+10;
		stablo[i].second=-1e9+10;
	}
	
	create();
	
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			int pov=query(1,0,pot,i,j);
			if(pov==-1){
				int test=max(stablo[pom[0]].second,stablo[pom[1]].second)-min(stablo[pom[0]].first,stablo[pom[1]].first);
				if(test<mini)mini=test;
			}else{
				int test=stablo[pov].second-stablo[pov].first;
				if(test<mini)mini=test;
			}
		}
	}
	
	cout<<mini;
	
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Incorrect 5 ms 504 KB Output isn't correct
4 Incorrect 5 ms 376 KB Output isn't correct
5 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
6 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
7 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)