////////////////////////////// Author:eldaee, coder_viper!!!!!!!!!!!!!!!!!!!!!!!!11
#pragma GCC optimize ("Ofast")
#include <bits/stdc++.h>
#define int long long
#define str string
#define vec vector
#define dou double
#define ld long double
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define YES cout << "YES" << '\n'
#define Yes cout << "Yes" << '\n'
#define NO cout << "NO" << '\n'
#define No cout << "No" << '\n'
#define gcd __gcd
#define all(x) x.begin(),x.end()
#define eldaee ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
void solve() {
str s;
cin >> s;
int n = (int) s.size();
int cnt[26] = {0};
for (int i = 0; i < n; i++) {
cnt[s[i] - 'a']++;
}
for (int i = 0; i < 26; i++) {
if (cnt[i] % 2 != 0) {
cout << -1 << "\n";
return;
}
}
str b(n, ' ');
vec<int> v;
for (int i = 0; i < n; i++) {
int c = s[i] - 'a';
int x = 0;
for (int j = (int) v.size() - 1; j >= 0; j--) {
if (s[v[j]] == s[i]) {
int idx = v[j];
b[idx] = '(';
b[i] = ')';
v.erase(v.begin() + j);
x = 1;
break;
}
}
if (x == 0) {
v.pb(i);
}
}
if (v.size() != 0) {
cout << -1 << "\n";
}
else {
cout << b << "\n";
}
}
signed main()
{
eldaee
solve();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |