Submission #56728

# Submission time Handle Problem Language Result Execution time Memory
56728 2018-07-12T08:54:42 Z 노영훈(#1616) Security Gate (JOI18_security_gate) C++11
0 / 100
2 ms 376 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MX=310, inf=2e9;


int n;
char S[MX], R[MX], T[MX];

bool valid(){
    int cnt=0, mn=0;
    for(int i=1; i<=n; i++){
        cnt+=T[i]=='(' ? 1 : -1;
        mn=min(mn, cnt);
    }
    return cnt==0 && mn>=0;
}

bool solve(){
    // cout<<(R+1)<<'\n';
    for(int i=1; i<=n; i++)
        for(int j=i; j<=n; j++){
            for(int k=1; k<=n; k++)
                T[k]=R[k];
            for(int k=i; k<=j; k++){
                T[k]=T[k]==')' ? '(' : ')';
            }
            if(valid()) return true;
        }
    return false;
}

int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin>>n>>(S+1);
    vector<int> P;
    for(int i=1; i<=n; i++) if(S[i]=='x') P.push_back(i);

    int ans=0;
    for(int i=0; i<(1<<(int)P.size()); i++){
        for(int j=1; j<=n; j++){
            R[j]=S[j];
        }
        for(int j=0; j<(int)P.size(); j++)
            if(i&(1<<j)) R[P[j]]='(';
            else R[P[j]]=')';
        ans+=solve();
    }
    cout<<ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -