# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1164001 | ozner77 | Security Gate (JOI18_security_gate) | Pypy 3 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef unordered_map<ll,ll> umll;
typedef set<ll> sl;
typedef unordered_set<ll> usl;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpii> vvpii;
typedef vector<vpll> vvpll;
typedef vector<vvi> vvvi;
typedef vector<vvl> vvvl;
vector<string> L;
vector<string> L2;
vector<vector<char>> L3;
void generar(vector<char> V){
bool ok=true;
for(ll i=0;i<V.size();i++){
if(V[i]=='x'){
V[i]='(';
generar(V);
V[i]=')';
generar(V);
ok=false;
break;
}
}
if(ok){
string uwu;
for(auto x:V){
uwu+=x;
}
L.pb(uwu);
}
}
bool check(vector<char> V){
ll c=0;
for(ll i=0;i<V.size();i++){
if(V[i]==')'){
c++;
}else{
c--;
}
if(c<0){
return false;
}
}
if(c>0){
return false;
}
return true;
}
void flip(ll n){
for(ll i=0;i<L2.size()-n;i++){
string cad=L2[i];
vector<char> cad2;
for(auto x:cad){
cad2.pb(x);
}
for(ll j=0;j<cad.size();j++){
ll c=0;
while(c<n+1){
if(cad2[j+c]==')'){
cad2[j+c]='(';
}else{
cad2[j+c]=')';
}
c++;
}
L3.pb(cad2);
c=0;
while(c<n+1){
if(cad2[j+c]==')'){
cad2[j+c]='(';
}else{
cad2[j+c]=')';
}
c++;
}
}
}
}
void check2(){
for(auto x:L){
bool ok=false;
ll c=0;
for(auto y:x){
if(y==')'){
c++;
}else{
c--;
}
if(c<0){
ok=true;
}
}
if(c>0){
ok=true;
}
if(ok){
L2.pb(x);
}
}
}
int main(){
ll n;
cin>>n;
string s;
cin>>s;
ll ans=0;
vector<char> caca;
for(auto x:s){
caca.pb(x);
}
generar(caca);
check2();
for(ll i=0;i<n;i++){
flip(i);
}
for(auto x:L3){
if(check(x)){
ans++;
}
}
cout<<ans;
}