#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
string s, ans = ")";
cin>>s;
int n = s.size();
for (int i = (1<<n) - 1; i >= 0; i--){
deque<int> de;
int pr = 0, can = 1;
for (int j = 0; j < n; j++){
int val = i & (1<<j);
if (val != 0) val = -1;
else val = 1;
pr += val;
if (pr < 0){
can = 0;
break;
}
}
for (int j = 0; j < n; j++){
int val = i & (1<<j);
if (val != 0) val = -1;
else val = 1;
pr += val;
if (pr < 0){
can = 0;
break;
}
}
for (int j = 0; j < n; j++){
if (!can) break;
int val = i & (1<<j);
if (val == 0){
de.push_back(j);
}
else{
if (s[de.back()] != s[j]){
can = 0;
break;
}
de.pop_back();
}
}
if (de.size() != 0) can = 0;
if (can){
string cmp;
for (int j = 0; j < n; j++){
if (!can) break;
int val = i & (1<<j);
if (val == 0){
cmp += '(';
}
else{
cmp += ')';
}
}
ans = min(ans, cmp);
}
}
if (ans == ")"){
cout<<-1;
}
else{
cout<<ans;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
13 ms |
336 KB |
Output is correct |
3 |
Correct |
4 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
13 ms |
336 KB |
Output is correct |
3 |
Correct |
4 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1231 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
13 ms |
336 KB |
Output is correct |
3 |
Correct |
4 ms |
336 KB |
Output is correct |
4 |
Incorrect |
1231 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |