Submission #1592008


Source Code Expand

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)1e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;

int f(vector< vector< int > >& gra,vector<int>& val,string& str,int L,int R,int root){
	int nodeIndex = gra.size();
	gra.push_back( vector<int>(0) );
	
	string Left,Center,Right;

	//左()
	int pos = 0;
	int cnt = 0;
	
	pos = 1;
	cnt = 1;
	while(cnt){
		if( str[ L+pos] == ')' ){
			--cnt;
		}else if( str[L+pos] == '('){
			++cnt;
		}
		++pos;
	}
	if( L+1 + 1 < L + pos-2 ){
		int res;
		res = f(gra,val,str,L+1,L + pos-2,nodeIndex);
		gra[nodeIndex].push_back( res );
	}else{
		gra[nodeIndex].push_back( -1 );
	}
	
	//[]
	int res = 0;
	++pos;
	while( str[ L+pos] != ']'){
		res = res*10 + str[L+pos]-'0';
		++pos;
	}
	val[nodeIndex] = res;
	++pos;
	
	//右の()
	if( L+pos+2 < R-1 ){
		int res;
		res = f(gra,val,str,L+pos+1,R-1,nodeIndex);
		gra[nodeIndex].push_back( res );
	}else{
		gra[nodeIndex].push_back( -1 );
	}

	return nodeIndex;
}

vector< vector<int> > Agra,Bgra;
vector<int> Aval(200,-1),Bval(200,-1);
vector<int> Cval(200,-1);
vector< vector<int > > Cgra;
int cal(vector<int>& val,int Aindex,int Bindex,int root){
	Cgra.push_back( vector<int>() );
	int nodeIndex = (int)Cgra.size() -1;
	
	if( Aval[Aindex] != -1 && Bval[Bindex] != -1 ){
		val[nodeIndex] = Aval[Aindex] + Bval[Bindex];
	}else{
		return nodeIndex;
	}

	if( Agra[Aindex][0] != -1 && Bgra[Bindex][0] != -1 ){
		int res = cal(val,Agra[Aindex][0],Bgra[Bindex][0],nodeIndex);
		Cgra[nodeIndex].push_back( res );
	}else{
		Cgra[nodeIndex].push_back( -1 );
	}

	if( Agra[Aindex][1] != -1 && Bgra[Bindex][1] != -1 ){
		int res = cal(val,Agra[Aindex][1],Bgra[Bindex][1],nodeIndex);
		Cgra[nodeIndex].push_back( res );
	}else{
		Cgra[nodeIndex].push_back( -1 );
	}

	return nodeIndex;
}

void view(int root){
	cout << "(";
	if( Cgra[root][0] != -1 ){
		view( Cgra[root][0] );
	}
	cout << ")[";
	cout << Cval[root] << "](";
	if( Cgra[root][1] != -1 ){
		view( Cgra[root][1] );
	}
	cout << ")";
}
void solve(){
	string Astr,Bstr;
	cin >> Astr >> Bstr;
	
	f(Agra,Aval,Astr,0,Astr.size()-1,0);
	f(Bgra,Bval,Bstr,0,Bstr.size()-1,0);

	
	cal(Cval,0,0,0);
	view(0);
	cout << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Submission Info

Submission Time
Task C - みさわさんの根付き木
User akarin55
Language C++14 (GCC 5.4.1)
Score 100
Code Size 3452 Byte
Status AC
Exec Time 2 ms
Memory 256 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 1 ms 256 KB
20_unbalanced_1 AC 1 ms 256 KB
20_unbalanced_2 AC 1 ms 256 KB
20_unbalanced_3 AC 1 ms 256 KB
21_small_unbalanced_0 AC 2 ms 256 KB
21_small_unbalanced_1 AC 1 ms 256 KB
21_small_unbalanced_2 AC 1 ms 256 KB
21_small_unbalanced_3 AC 1 ms 256 KB