답안 #66388

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
66388 2018-08-10T11:06:52 Z KLPP Poklon (COCI17_poklon7) C++14
120 / 120
412 ms 136880 KB
#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

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]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 2 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 2 ms 488 KB Output is correct
5 Correct 2 ms 548 KB Output is correct
6 Correct 2 ms 588 KB Output is correct
7 Correct 2 ms 632 KB Output is correct
8 Correct 2 ms 732 KB Output is correct
9 Correct 2 ms 744 KB Output is correct
10 Correct 2 ms 752 KB Output is correct
11 Correct 6 ms 1296 KB Output is correct
12 Correct 8 ms 1452 KB Output is correct
13 Correct 22 ms 3824 KB Output is correct
14 Correct 42 ms 7580 KB Output is correct
15 Correct 36 ms 7580 KB Output is correct
16 Correct 150 ms 22228 KB Output is correct
17 Correct 299 ms 49372 KB Output is correct
18 Correct 337 ms 65596 KB Output is correct
19 Correct 372 ms 80088 KB Output is correct
20 Correct 412 ms 136880 KB Output is correct