Submission #1293971

#TimeUsernameProblemLanguageResultExecution timeMemory
1293971okahak71Match (CEOI16_match)C++20
37 / 100
2094 ms1064 KiB
#include <bits/stdc++.h>
#define ll long long
#define vec vector
#define pb push_back
#define pll array<ll, 2>
#define all(X) X.begin(), X.end()
#define allr(X) X.rbegin(), X.rend()
using namespace std;

const ll inf = 1e18;
const ll mod = 1e9 + 7;

void _(){
    string s; cin >> s;
    stack<ll> st; string ans = "";
    for(ll i = 0 ; i < s.size() ; i++){
        if(!st.size() or s[st.top()] != s[i]) st.push(i);
        else st.pop();
    }
    if(st.size()){
        cout << -1 << endl;
        return;
    }st = stack<ll>(); stack<ll>stt;
    for(ll i = 0 ; i < s.size() ; i++){
        stt = st; stt.push(i);
        for(ll j = i + 1 ; j < s.size() ; j++){
            if(!stt.empty() and s[stt.top()] == s[j]) stt.pop();
            else stt.push(j);
        }
        if(!stt.empty()) ans += ')', st.pop();
        else ans += '(', st.push(i);
    }
    cout << ans << endl;
}

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); _();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...