| # | Time | Username | Problem | Language | Result | Execution time | Memory | 
|---|---|---|---|---|---|---|---|
| 407116 | 79brue | Security Gate (JOI18_security_gate) | C++14 | 1 ms | 204 KiB | 
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
char s[102];
int pref[102];
int ans;
void dfs(int x){
    if(x == n+1){
        int firstNegative = 101, lastNegative = -1;
        for(int i=1; i<=n; i++) if(pref[i] < 0) firstNegative = min(firstNegative, i);
        for(int i=1; i<=n; i++) if(pref[i] - pref[n] < 0) lastNegative = i;
        bool able = 0;
        for(int i=1; i<=n && i<=firstNegative; i++){
            bool good = 0;
            for(int j=i; j<=n; j++){
                if(pref[j] > 2 * pref[i-1]) break;
                if(pref[n] - 2 * (pref[j] - pref[i-1]) == 0 && j > lastNegative){
                    good = 1;
                    break;
                }
            }
            if(good){
                able = 1;
                break;
            }
        }
        if(able) ans++;
        return;
    }
    if(s[x] == '(' || s[x] == ')'){
        pref[x] = pref[x-1] + (s[x] == '(' ? 1 : -1);
        dfs(x+1);
        return;
    }
    s[x] = '('; pref[x] = pref[x-1] + 1;
    dfs(x+1);
    s[x] = ')'; pref[x] = pref[x-1] - 1;
    dfs(x+1);
    s[x] = 'x';
    return;
}
int main(){
    scanf("%d %s", &n, s+1);
    if(n%2){
        printf("0");
        return 0;
    }
    dfs(1);
    printf("%d", ans);
}
Compilation message (stderr)
| # | 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... | ||||
