Submission #609464

#TimeUsernameProblemLanguageResultExecution timeMemory
609464VanillaMatch (CEOI16_match)C++17
37 / 100
2082 ms540 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e3 + 2;
string rs;
string s;
int n;

int main() {
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> s;
    n = s.size();
    rs = string(n, '0');
    stack <char> st;
    for (int i = 0; i < n; i++){
        auto check = [&, st] () mutable -> bool {
            st.push(s[i]);
            for (int j = i + 1; j < n; j++){
                if (!st.empty() && s[j] == st.top()) st.pop();
                else st.push(s[j]);
            }  
            return st.empty();
        };
        if (check()) {
            rs[i] = '(';
            st.push(s[i]);
        }
        else {
            rs[i] = ')';
            if (!st.empty() && st.top() == s[i]) st.pop();
            else {
                cout << "-1\n";
                return 0;
            }
        }
    }
    if (st.empty()) cout << rs;
    else cout << "-1";

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...