Submission
Status:
[PPPPPPPPPx]
Subtask/Task Score:
{0/100}
Score: 0
User: KantaponZ
Problemset: composite tree
Language: cpp
Time: 0.002 second
Submitted On: 2026-03-10 11:18:00
#include <bits/stdc++.h>
using namespace std;
const int nx = 1e3 + 5;
int tree1[4*nx], tree2[4*nx], res[4*nx];
void solve1(int idx) {
if (idx == 1) {
char c; cin >> c;
tree1[idx] = c - '0';
cin >> c;
solve1(idx*2);
cin >> c;
solve1(idx*2+1);
return;
}
char c; cin >> c;
if (c >= '1' && c <= '9') {
tree1[idx] = c - '0';
cin >> c;
solve1(idx*2);
cin >> c;
solve1(idx*2+1);
cin >> c;
return;
}
}
void solve2(int idx) {
if (idx == 1) {
char c; cin >> c;
tree2[idx] = c - '0';
cin >> c;
solve2(idx*2);
cin >> c;
solve2(idx*2+1);
return;
}
char c; cin >> c;
if (c >= '1' && c <= '9') {
tree2[idx] = c - '0';
cin >> c;
solve2(idx*2);
cin >> c;
solve2(idx*2+1);
cin >> c;
return;
}
}
void ans(int idx) {
if (res[idx] == 0) return;
cout << res[idx];
cout << '(';
ans(idx*2);
cout << ')';
cout << '(';
ans(idx*2+1);
cout << ')';
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
solve1(1);
solve2(1);
for (int i = 0; i < 4*nx; i++) {
if (tree1[i] == 0 || tree2[i] == 0) continue;
res[i] = tree1[i] + tree2[i];
}
ans(1);
}