Submission #537670

#TimeUsernameProblemLanguageResultExecution timeMemory
537670zaneyuSecurity Gate (JOI18_security_gate)C++14
30 / 100
961 ms332 KiB
/*input 3 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; int mn=INF; REP1(i,n){ if(s[i-1]=='(') ++x; else --x; pf[i]=x; MNTO(mn,pf[i]); } int r=0; for(int i=n;i>=0;i--){ if(pf[i]<pf[n]){ r=i; break; } } if(pf[n]==0 and mn==0){ return true; } REP(i,n+2) pm[i]=0; for(int i=r;i>=0;i--){ pm[i]=max(pm[i+1],pf[i]); } REP1(j,n){ if(pf[j-1]<0) break; 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; } } } return false; } int main(){ ios::sync_with_stdio(false),cin.tie(0); int n; cin>>n; if(n%2){ cout<<0; return 0; } 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...