Submission #66388

#TimeUsernameProblemLanguageResultExecution timeMemory
66388KLPPPoklon (COCI17_poklon7)C++14
120 / 120
412 ms136880 KiB
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<stdio.h>
#include<stack>
using namespace std;
typedef long long int lld;
typedef pair<lld,int> Z;
lld scales[10000000][2];
Z maximo(Z x,Z y){
	if(x.second<y.second)return maximo(y,x);
	Z a,b;
	a=x;
	b=y;
	a.second-=b.second;
	if(a.second>32){
		return x;	
	}
	for(int i=0;i<a.second;i++){
		a.first*=2;
	}
	if(a.first>b.first)return x;
	return y;
	
}
pair<lld,int> ans(int x){
	Z r1;
	if(scales[x][0]>0){
		r1=ans(scales[x][0]);
	}else r1=pair<lld,int>(-scales[x][0],0);
	Z r2;
	if(scales[x][1]>0){
		r2=ans(scales[x][1]);
	}else r2=pair<lld,int>(-scales[x][1],0);
	Z R=maximo(r1,r2);
	R.second++;
	return R;
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld %lld",&scales[i+1][0],&scales[i+1][1]);
	}
	Z R=ans(1);
	stack<int> b1;
	while(R.first>0){
		b1.push(R.first%2);
		R.first/=2;
	}
	while(!b1.empty()){
		cout<<b1.top();b1.pop();
	}
	for(int i=0;i<R.second;i++)cout<<"0";
	cout<<endl;
	return 0;
}

Compilation message (stderr)

poklon.cpp: In function 'int main()':
poklon.cpp:42:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
  ~~~~~^~~~~~~~~
poklon.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld",&scales[i+1][0],&scales[i+1][1]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...