이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <stack>
#include <algorithm>
using namespace std;
int n;
string s;
stack <int> S;
void generuj() {
bool t = true;
string a = "";
string w = "))))))))))))))))))";
for (int bitmask = 1 << (n-1); bitmask < (1 << n); bitmask++) {
a.clear();
t = true;
for (int i = n - 1; i >= 0; i--) {
if (bitmask & (1 << i)) {
S.push(n - i - 1);
a.insert(a.size(), "(");
}
else {
a.insert(a.size(), ")");
if (S.empty()) {
t = false;
break;
}
int v = S.top();
S.pop();
if (s[v] != s[n - i - 1]) {
t = false;
break;
}
}
}
if (S.empty() && t == true) {
w = min(w, a);
}
while (!S.empty()) S.pop();
}
if (w == "))))))))))))))))))") {
cout << -1;
return;
}
cout << w;
}
int main()
{
cin >> s;
n = s.size();
if (n % 2 == 1) {
cout << -1;
return 0;
}
generuj();
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |