-
Notifications
You must be signed in to change notification settings - Fork 0
/
2800.cpp
35 lines (35 loc) · 801 Bytes
/
2800.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include <iostream>
#include <string>
#include <stack>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;
string s;
vector<pair<int,int>> v;
int main(){
cin >> s;
stack<int> st;
for(int i=0;i<s.size();i++){
char c = s[i];
if(c=='(') st.push(i);
else if(c==')'){
v.push_back({st.top(),i});
st.pop();
}
}
set<string> ans;
int n = v.size();
for(int i=1;i<(1<<n);i++){
vector<bool> erased(s.size());
for(int j=0;j<n;j++){
if(((1<<j)&i)>0) erased[v[j].first]=erased[v[j].second]=1;
}
string tmp;
for(int j=0;j<s.size();j++){
if(!erased[j]) tmp+=s[j];
}
ans.insert(tmp);
}
for(auto a : ans) cout << a << '\n';
}