이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "bits/stdc++.h"
using namespace std;
const int mxN = 20;
int ar[mxN];
int main() {
string S;
cin >> S;
int N = S.size();
string ans(N, ')');
for (int i = 0; i < (1 << N); i ++) {
vector<int> match(N);
stack<int> open;
string bit;
int balance = 0;
int f = 1;
for (int j = 0; j < N; j ++) {
int bt = (i >> j) & 1;
if (bt) {
balance ++;
} else {
balance --;
}
if (0 > balance) {
f = 0;
break;
}
if (bt) {
open.push(j);
bit += '(';
} else {
match[open.top()] = j;
match[j] = open.top();
open.pop();
bit += ')';
}
}
if (!f || balance) {
continue;
}
for (int j = 0; j < N; j ++) {
int k = match[j];
if (S[j] ^ S[k]) {
f = 0;
}
}
if (f) {
ans = min(ans, bit);
}
}
if (ans[0] != ')') {
cout << ans << endl;
} else {
cout << -1 << endl;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |