Submission #476692

# Submission time Handle Problem Language Result Execution time Memory
476692 2021-09-28T08:30:52 Z wiktoria_bazan Match (CEOI16_match) C++14
10 / 100
90 ms 268 KB
#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;

int n;
string s;
stack <int> S;

void generuj() {
    bool t = true;
    string a = "";
    string w = "))))))))))))))))))";
    for (int bitmask = 1 << (n-1); bitmask < (1 << n); bitmask++) {
        a.clear();
        t = true;
        for (int i = n - 1; i >= 0; i--) {
            if (bitmask & (1 << i)) {
                S.push(n - i - 1);
                a.insert(a.size(), "(");
            }
            else {
                a.insert(a.size(), ")");
                if (S.empty()) {
                    t = false;
                    break;
                }
                int v = S.top();
                S.pop();
                if (s[v] != s[n - i - 1]) {
                    t = false;
                    break;
                }
            }
        }
        if (S.empty() && t == true) {
            w = min(w, a);
        }
        while (!S.empty()) S.pop();
    }
    if (w == "))))))))))))))))))") {
        cout << -1;
        return;
    }
    cout << w;
}

int main()
{
    cin >> s;
    n = s.size();
    if (n % 2 == 1) {
        cout << -1;
        return 0;
    }
    generuj();
}


# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Incorrect 90 ms 268 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 7 ms 204 KB Output is correct
3 Correct 2 ms 204 KB Output is correct
4 Incorrect 90 ms 268 KB Output isn't correct
5 Halted 0 ms 0 KB -