Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
797 B
21
Indexable
Never
#include <bits/stdc++.h>
using namespace std;
bool ok(string s) {
    int now = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == '(') now++;
        else {
            now--;
            if (now < 0) return false;
        }
    }
    return now == 0;
}
int main() {
    freopen("brackets.in", "r", stdin);
    freopen("brackets.out", "w", stdout);
    string s;
    cin >> s;
    int n = s.size(), ans = 0;
    for (int i = 0; i < (1<<n); i++) {
        string t = s;
        for (int j = 0; j < n; j++) {
            if (s[j] == '?') {
                if (i&(1<<j)) t[j] = ')';
                else t[j] = '(';
                
            }
        }
        if (ok(t)) {
//            cout << t << endl;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}