이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
int N;
char s[MAXN];
char ans[MAXN];
bool ava(stack<char> st, int x) {
for(int i = x; i < N; i++) {
if(!st.empty() && s[i] == st.top()) st.pop();
else st.push(s[i]);
}
return st.empty();
}
int main() {
cin >> s;
for(N = 0; s[N]; N++);
stack<char> st;
for(int i = 0; i < N; i++) {
st.push(s[i]);
if(ava(st, i + 1)) ans[i] = '(';
else {
ans[i] = ')';
st.pop();
if(st.empty() || st.top() != s[i]) {
cout << -1;
return 0;
}
st.pop();
}
}
if(st.empty())
for(int i = 0; i < N; i++) cout << ans[i];
else cout << -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... |