제출 #97085

#제출 시각아이디문제언어결과실행 시간메모리
97085karlopuhTurnir (COCI17_turnir)C++14
30 / 100
3052 ms12724 KiB
#include <bits/stdc++.h>
using namespace std;

vector<int> niz;
vector<int> sorted;
vector<int> rj;
int n;
int N;

int main(){
	cin>>n;
	N=pow(2,n);
	for(int i=0;i<N;i++){
		int broj;
		cin>>broj;
		niz.push_back(broj);
		sorted.push_back(broj);
		rj.push_back(4);
	}
	
	sort(sorted.begin(),sorted.end());
	
	for(int i=0;i<N;i++){
		if(niz[i]==sorted[sorted.size()-1]){
			rj[i]=0;
		}
	}
	
	
	for(int b=0;b<N;b++){
	if(rj[b]!=4)continue;
		for(int i=1;i<=n;i++){
			bool moj=false;
			int treba=N/(pow(2,i))-1;
			for(int j=sorted.size()-1;j>=0;j--){
				if(sorted[j]<=niz[b] && moj){
					treba--;
				}
				if(!moj && sorted[j]<=niz[b])moj=true;
				if(treba<=0){
					for(int z=0;z<N;z++){
						if(niz[z]==niz[b]){
							rj[z]=min(rj[b],i);
						}
					}
					rj[b]=min(rj[b],i);
					break;
				}
			
			}
		}	
	}			
	
	for(int i=0;i<N;i++){
		cout<<rj[i]<<" ";
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...