이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |