Submission #1176854


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define FOR(i,a,n) for(int i=a,i##_len=(int)(n);i<i##_len;++i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i=(int)(n);i>=0;--i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

struct node {
    string left;
    int n;
    string right;
};
node compile(string s) {
    node ret;
    int k=1;
    string tmp="";
    int i;
    for(i=1;i<SZ(s);i++) {
        if(s[i]=='(') k++;
        if(s[i]==')') k--;
        if(k==0) break;
        tmp+=s[i];
    }
    ret.left=tmp;
    tmp="";
    i+=2;
    for(;i<SZ(s);i++) {
        if(s[i]==']') break;
        tmp+=s[i];
    }
    ret.n=stoi(tmp);
    tmp="";
    i+=2;
    k=1;
    for(;i<SZ(s);i++) {
        if(s[i]=='(') k++;
        if(s[i]==')') k--;
        if(k==0) break;
        tmp+=s[i];
    }
    ret.right=tmp;
    return ret;
}
string decompile(node n) {
    return "("+n.left+")["+to_string(n.n)+"]("+n.right+")";
}
node dfs(string a,string b) {
    node ret;
    node A=compile(a),B=compile(b);
    if(A.left=="" || B.left=="") ret.left="";
    else {
        ret.left=decompile(dfs(A.left,B.left));
    }
    if(A.right=="" || B.right=="") ret.right="";
    else {
        ret.right=decompile(dfs(A.right,B.right));
    }
    ret.n=A.n+B.n;
    return ret;
}
signed main() {
    string s,t;
    cin>>s>>t;
    cout<<decompile(dfs(s,t))<<endl;
    return 0;
}

Submission Info

Submission Time
Task C - みさわさんの根付き木
User algon
Language C++14 (GCC 5.4.1)
Score 100
Code Size 2937 Byte
Status AC
Exec Time 2 ms
Memory 512 KB

Judge Result

Set Name All
Score / Max Score 100 / 100
Status
AC × 53
Set Name Test Cases
All 0_sample_0, 0_sample_1, 0_sample_2, 0_sample_3, 0_sample_4, 10_random_00, 10_random_01, 10_random_02, 10_random_03, 10_random_04, 10_random_05, 10_random_06, 10_random_07, 10_random_08, 10_random_09, 10_random_10, 10_random_11, 10_random_12, 10_random_13, 10_random_14, 10_random_15, 10_random_16, 10_random_17, 10_random_18, 10_random_19, 10_random_20, 10_random_21, 10_random_22, 10_random_23, 10_random_24, 10_random_25, 10_random_26, 10_random_27, 10_random_28, 10_random_29, 10_random_30, 10_random_31, 10_random_32, 10_random_33, 10_random_34, 10_random_35, 10_random_36, 10_random_37, 10_random_38, 10_random_39, 20_unbalanced_0, 20_unbalanced_1, 20_unbalanced_2, 20_unbalanced_3, 21_small_unbalanced_0, 21_small_unbalanced_1, 21_small_unbalanced_2, 21_small_unbalanced_3
Case Name Status Exec Time Memory
0_sample_0 AC 1 ms 256 KB
0_sample_1 AC 1 ms 256 KB
0_sample_2 AC 1 ms 256 KB
0_sample_3 AC 1 ms 256 KB
0_sample_4 AC 1 ms 256 KB
10_random_00 AC 1 ms 256 KB
10_random_01 AC 1 ms 256 KB
10_random_02 AC 1 ms 256 KB
10_random_03 AC 1 ms 256 KB
10_random_04 AC 1 ms 256 KB
10_random_05 AC 1 ms 256 KB
10_random_06 AC 1 ms 256 KB
10_random_07 AC 1 ms 256 KB
10_random_08 AC 1 ms 256 KB
10_random_09 AC 1 ms 256 KB
10_random_10 AC 1 ms 256 KB
10_random_11 AC 1 ms 256 KB
10_random_12 AC 1 ms 256 KB
10_random_13 AC 1 ms 256 KB
10_random_14 AC 1 ms 256 KB
10_random_15 AC 1 ms 256 KB
10_random_16 AC 1 ms 256 KB
10_random_17 AC 1 ms 256 KB
10_random_18 AC 1 ms 256 KB
10_random_19 AC 1 ms 256 KB
10_random_20 AC 1 ms 256 KB
10_random_21 AC 1 ms 256 KB
10_random_22 AC 1 ms 256 KB
10_random_23 AC 1 ms 256 KB
10_random_24 AC 1 ms 256 KB
10_random_25 AC 1 ms 256 KB
10_random_26 AC 1 ms 256 KB
10_random_27 AC 1 ms 256 KB
10_random_28 AC 1 ms 256 KB
10_random_29 AC 1 ms 256 KB
10_random_30 AC 1 ms 256 KB
10_random_31 AC 1 ms 256 KB
10_random_32 AC 1 ms 256 KB
10_random_33 AC 1 ms 256 KB
10_random_34 AC 1 ms 256 KB
10_random_35 AC 1 ms 256 KB
10_random_36 AC 1 ms 256 KB
10_random_37 AC 1 ms 256 KB
10_random_38 AC 1 ms 256 KB
10_random_39 AC 1 ms 256 KB
20_unbalanced_0 AC 2 ms 512 KB
20_unbalanced_1 AC 1 ms 256 KB
20_unbalanced_2 AC 1 ms 256 KB
20_unbalanced_3 AC 2 ms 512 KB
21_small_unbalanced_0 AC 2 ms 512 KB
21_small_unbalanced_1 AC 1 ms 256 KB
21_small_unbalanced_2 AC 1 ms 256 KB
21_small_unbalanced_3 AC 2 ms 512 KB