Submission #1117715

#TimeUsernameProblemLanguageResultExecution timeMemory
1117715vjudge1Match (CEOI16_match)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h>
#define GOOD_LUCK ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define itn int
#define INF 100000000
#define MOD 998244353
#define MAX 103
#define endl "\n"
#define ff first
#define ss second
using namespace std;

int temp;

signed main() {

	GOOD_LUCK

    int t;
	t = 1;
//	cin >> t;
    while (t--) {
        int n;
        string a;
        cin >> a;
        n = a.size();
        if (n % 2 != 0) {
        	cout << -1;
        	return 0;
		}
        stack <char> s;
        map <char, int> m;
        for (int i=0; i < n; i++) {
        	m[a[i]]++;
        	if (s.empty()) s.push(a[i]);
        	else if (s.top() == a[i]) s.pop();
        	else s.push(a[i]);
		}
		/*for (auto i : m) {
			cout << i.ff << ' ' << i.ss;
			cout << endl;
		}*/
		if (s.empty()) {
			for (auto i : m) {
				if (i.ss % 2 != 0) {
					cout << -1;
					return 0;
				}
			}
			string ans = "";
			for (int i=0; i < n; i++) {
				if (m[a[i]] > 0) {
					ans = ans + '(';
					m[a[i]]-=2;
				}
				else {
					ans += ')';
				}
			}
			cout << ans;
		}
		else {
			cout << -1;
		}
	}

    return 0;
}
// Problem C
// by Ekber_Ekber
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...