Submission #1117715

# Submission time Handle Problem Language Result Execution time Memory
1117715 2024-11-24T07:48:10 Z vjudge1 Match (CEOI16_match) C++17
0 / 100
1 ms 336 KB
#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 time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Incorrect 1 ms 336 KB Output isn't correct
3 Halted 0 ms 0 KB -