#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
string s;
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){
for (int j = 0; j < n; j++){
if (!can) break;
int val = i & (1<<j);
if (val == 0){
cout<<'(';
}
else{
cout<<')';
}
}
return 0;
}
}
cout<<-1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |