이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int nx=1e5+5;
int n;
string s;
stack<int> st;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>s;
n=s.size();
for (auto x:s)
{
if (st.empty()||st.top()!=x) st.push(x);
else st.pop();
}
if (!st.empty()) return cout<<-1, 0;
while (!st.empty()) st.pop();
for (int i=0; i<n; i++)
{
if (st.empty()||st.top()!=s[i]) cout<<'(', st.push(s[i]);
else
{
stack<int> tmp=st;
tmp.push(s[i]);
for (int j=i+1; j<n; j++)
{
if (tmp.empty()||tmp.top()!=s[j]) tmp.push(s[j]);
else tmp.pop();
}
if (tmp.empty()) cout<<'(', st.push(s[i]);
else cout<<')', st.pop();
}
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |