// +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+ \\
/* Some Makoto Shinkai's :
“Who cares if we can't see any sunshine? I want you more than any blue sky!!!”
- Tenki no Ko
"By the time the date is over, the comet will be visible in the sky."
- Kimi no Nawa
“No matter what happens, even if the stars fall, I will live.”
- Byōsoku 5 Centimeter
*/
#include <bits/stdc++.h>
#define Raveluk ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define tii tuple<int,int,int>
#define g1 get<0>
#define g2 get<1>
#define g3 get<2>
#define qf q.front()
#define all(x) (x).begin(), (x).end()
using namespace std;
ll n,anu[1000001][2],freq[1000001],f1,f3,len1,len3;
string conv(ll bil){
if(bil == 0) return "";
if(bil%2 == 1) return conv(bil/2) + '1';
return conv(bil/2) + '0';
}
string gaskan(ll node){
int i;
if(node < 0) return conv(abs(node));
string s1 = gaskan(anu[node][0]);
string s3 = gaskan(anu[node][1]);
if(anu[node][0] < 0) f1 = 0;
else f1 = freq[anu[node][0]];
if(anu[node][1] < 0) f3 = 0;
else f3 = freq[anu[node][1]];
len1 = s1.length(),len3 = s3.length();
if(len1+f1 > len3+f3){
freq[node] = f1+1;
return s1;
}
if(len3+f3 > len1+f1){
freq[node] = f3+1;
return s3;
}
if(len1 == len3){
for(i=0;i<len1;i++){
if(s3[i] > s1[i]){
freq[node] = f3+1;
return s3;
}
}
freq[node] = f1+1;
return s1;
}
if(len1 > len3){
for(i=0;i<len3;i++){
if(s3[i] > s1[i]){
freq[node] = f3+1;
return s3;
}
}
freq[node] = f1+1;
return s1;
}
if(len3 > len1){
for(i=0;i<len1;i++){
if(s1[i] > s3[i]){
freq[node] = f1+1;
return s1;
}
}
freq[node] = f3+1;
return s3;
}
}
int main()
{
Raveluk
cin>>n;
int i;
for(i=1;i<=n;i++) cin>>anu[i][0]>>anu[i][1];
cout<<gaskan(1);
for(i=0;i<freq[1];i++) cout<<0;
return 0;
}
Compilation message (stderr)
poklon.cpp: In function 'std::string gaskan(long long int)':
poklon.cpp:84:1: warning: control reaches end of non-void function [-Wreturn-type]
84 | }
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |