Submission #952285

#TimeUsernameProblemLanguageResultExecution timeMemory
952285Doncho_BonbonchoPoklon (COCI17_poklon7)C++14
60 / 120
191 ms64768 KiB
#include <bits/stdc++.h>
using namespace std;

template< class T, class T2 > inline bool chkmin( T& a, const T2& b ){ return a > b ? a = b, 1 : 0; }
template< class T, class T2 > inline bool chkmax( T& a, const T2& b ){ return a < b ? a = b, 1 : 0; }

#ifndef LOCAL
#define cerr if( false )cerr
#endif

#define out(x) #x << " = " << x << "  "

typedef long long ll;

const int MAX_N = 1e6 + 42;
const ll mod = 1e9 + 7;

ll L[MAX_N];
ll R[MAX_N];

__int128 f( int curr ){

	cerr << " in " << out( curr ) << out( L[curr] ) << out( R[curr] ) << endl;
	__int128 lSum = -1 * L[curr];
	if( L[curr] > 0 ){
		lSum = f( L[curr] );
	}

	__int128 rSum = -1 * R[curr];
	if( R[curr] > 0 ){
		rSum = f( R[curr] );
	}

	//cerr << "out " << out( curr ) << out( lSum ) << out( rSum ) << endl;
	//cerr << out( std::max( lSum, rSum ) * 2 ) << endl;
	return std::max( lSum, rSum ) * 2;
}

int main (){

#ifndef LOCAL
	std::ios_base::sync_with_stdio( false ); std::cin.tie( NULL ); std::cout.tie( NULL );
#endif

	int n;
	std::cin >> n;
	for( int i=1 ; i <= n ; i++ ){
		std::cin >> L[i] >> R[i];
	}

	__int128 nas = f( 1 );
	//std::cout << f( 1 ) << endl;
	std::string s;
	while( nas ){
		s += ( nas & 1 ? "1" : "0" );
		nas >>= 1;
	}
	reverse( s.begin(), s.end() );
	std::cout << s << endl;

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...