Last active
August 29, 2015 14:03
-
-
Save niyarin/a3067d19f5d89ff4ad39 to your computer and use it in GitHub Desktop.
aoj_1188
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
#include<string> | |
#include<algorithm> | |
#include<vector> | |
using namespace std; | |
int main(void){ | |
int nest,len; | |
string S; | |
string temp; | |
int N; | |
int sum; | |
vector< vector<int> > data(10000,vector<int>(0)); | |
cin>>N; | |
temp=""; | |
for (int i =0;i<N;i++){ | |
cin>>S; | |
nest = 0; | |
for (int k=0;k<10000;k++) while( !data[k].empty() ) data[k].pop_back(); | |
for (int j=0;j<S.length();j++){ | |
if (S[j] == '['){ | |
nest++; | |
} else if (S[j] == ']'){ | |
if (nest>0){ | |
sum = 0; | |
len = data[nest].size(); | |
sort(data[nest].begin(),data[nest].end()); | |
for (int h=0;h<(len+1)/2;h++){ | |
sum += data[nest][h]; | |
} | |
data[nest-1].push_back(sum); | |
} | |
while (!data[nest].empty() )data[nest].pop_back(); | |
nest--; | |
} else { | |
temp += S[j]; | |
if (S[j+1] == ']'){ | |
data[nest].push_back( (stoi(temp)+1) /2 ); | |
temp = ""; | |
} | |
} | |
} | |
cout<<data[0][0]<<endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment