Submission

Status:

[-SSSSSSSSS]

Subtask/Task Score:

{0/100}

Score: 0

User: meme_boi2

Problemset: composite tree

Language: cpp

Time: 0.003 second

Submitted On: 2026-02-04 11:57:55

#include <bits/stdc++.h>
using namespace std;
const int MAXN =1e4+1;
int tree[2][4*MAXN];
void print(int idx){
    if(tree[0][idx] != -1 && tree[1][idx] != -1){
        cout << tree[0][idx] + tree[1][idx];
    }else{
        cout << ')';
        return;
    }
    cout << '(';
    print(2*idx);
    cout << "(";
    print(2*idx+1);
    if(idx != 1) cout << ')';
}
int32_t main(){
    cin.tie(nullptr)->sync_with_stdio(0);
    string txt;
    memset(tree,-1,sizeof(tree));
    cin >> txt;
    int idx = 1;
    for(int i = 0; i < txt.length(); i++){
        if(isdigit(txt[i])){
            tree[0][idx] = txt[i] - '0';
        }
        else if(txt[i] == '('){
            if(txt[i-1] == ')'){
                idx = 2*idx + 1;
            }else{
                idx = 2*idx;
            }
        }else{
            idx /= 2;
        }
    }
   cin >> txt;
    idx = 1;
    for(int i = 0; i < txt.length(); i++){
        if(isdigit(txt[i])){
            tree[1][idx] = txt[i] - '0';
        }
        else if(txt[i] == '('){
            if(txt[i-1] == ')'){
                idx = 2*idx + 1;
            }else{
                idx = 2*idx;
            }
        }else{
            idx /= 2;
        }
    } 
    for(int i = 1;i <= 16;i ++) cout << tree[0][i] << ' '; cout << '\n';
    for(int i = 1; i <= 16; i++) cout << tree[1][i] << ' '; cout << '\n';
    print(1);
    
}
/*
5(2(8()())())(1(6(2()())(3()()))())
3(4()())(8(1(2()())())(3()()))

8(6()())(9(7(4()())())())))
8(6()())(9(7(4()())())())
*/