이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
#define sz(x) ((int)size(x))
#define trace(x) cout << #x << ": " << (x) << endl;
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
string s;
cin >> s;
int n = sz(s);
string ans;
ans.resize(n, '?');
auto check = [](string s, string ans) {
int n = sz(s);
vector<int> st;
for (int i = 0; i < n; ++i) {
if (ans[i] == '?') {
if (st.empty()) {
st.push_back(i);
} else {
if (s[st.back()] == s[i]) {
st.pop_back();
} else {
st.push_back(i);
}
}
} else if (ans[i] == '('){
st.push_back(i);
} else {
if (st.empty() || s[st.back()] != s[i]) {
return false;
}
st.pop_back();
}
}
return st.empty();
};
if (!check(s, ans)) {
cout << -1;
return 0;
}
for (int i = 0; i < n; ++i) {
ans[i] = '(';
if (check(s, ans)) continue;
ans[i] = ')';
}
cout << ans;
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... |