This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*input
10
xx(xx()x(x
*/
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define MNTO(x,y) x=min(x,y)
#define MXTO(x,y) x=max(x,y)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define ll long long
#define ld long double
#define sz(x) (int)x.size()
#define pii pair<ll,ll>
#define pdd pair<ld,ld>
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
const int INF=0x3f3f3f3f;
const int maxn=100+5;
int pf[maxn],pm[maxn];
bool check(string s){
int n=sz(s);
int x=0;
REP1(i,n){
if(s[i-1]=='(') ++x;
else --x;
pf[i]=x;
}
int r=0;
for(int i=n;i>=0;i--){
if(pf[i]<pf[n]){
r=i;
break;
}
}
pm[r+1]=0;
for(int i=r;i>=0;i--){
pm[i]=max(pm[i+1],pf[i]);
}
REP1(j,n){
int mx=pm[j];
for(int i=max(r,j);i<=n;i++){
MXTO(mx,pf[i]);
if(mx>pf[j-1]*2){
break;
}
if((2*pf[j-1]-2*pf[i]+pf[n])==0){
return true;
}
}
if(pf[j]<0) break;
}
return false;
}
int main(){
ios::sync_with_stdio(false),cin.tie(0);
int n;
cin>>n;
string s;
cin>>s;
vector<int> v;
REP(i,n){
if(s[i]=='x') v.pb(i);
}
int ans=0;
REP(i,(1<<sz(v))){
string tmp=s;
REP(j,sz(v)){
if(i&(1<<j)) s[v[j]]='(';
else s[v[j]]=')';
}
ans+=check(s);
s=tmp;
}
cout<<ans<<'\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |