This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int a[100100];
vector<int> pos[26];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
string s;
cin >> s;
int n = s.size();
for (int i = 0;i < n;i++) {
pos[s[i] - 'a'].push_back(i);
}
for (int i = 0;i < 26;i++) {
int m = pos[i].size();
if (m & 1) {
cout << -1;
return 0;
}
for (int j = 0;j < m / 2;j++) {
a[pos[i][j]] = -1;
}
for (int j = m / 2;j < m;j++) {
a[pos[i][j]] = 1;
}
}
stack<char> st;
for (int i = 0;i < n;i++) {
if (a[i] == -1) {
st.push(s[i]);
}
else {
if (st.empty()) {
cout << -1;
return 0;
}
if (st.top() != s[i]) {
cout << -1;
return 0;
}
st.pop();
}
}
for (int i = 0;i < n;i++) {
cout << "()"[a[i] == 1];
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |