이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long int64;
const int maxn = 2e3 + 2;
string rs;
string s;
int n;
int main() {
ios::sync_with_stdio(0); cin.tie(0);
cin >> s;
n = s.size();
rs = string(n, '0');
stack <char> st;
for (int i = 0; i < n; i++){
auto check = [&, st] () mutable -> bool {
st.push(s[i]);
for (int j = i + 1; j < n; j++){
if (!st.empty() && s[j] == st.top()) st.pop();
else st.push(s[j]);
}
return st.empty();
};
if (check()) {
rs[i] = '(';
st.push(s[i]);
}
else {
rs[i] = ')';
if (!st.empty() && st.top() == s[i]) st.pop();
else {
cout << "-1\n";
return 0;
}
}
}
if (st.empty()) cout << rs;
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... |