#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #define int long long
#define ll long long
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
const int oo = 1e9 + 9;
const int MAX = 4e5 + 5, LOGMAX = 20, B = 441, MOD = 998244353;
void solve(){
string s; cin >> s;
int n = s.size();
reverse(all(s));
for(int mask = (1 << n) - 1; mask >= 0; mask--){
stack<int> st;
bool b = 1;
for(int i = n - 1; i >= 0; i--){
if((1 << i) & mask) st.push(i);
else{
if(st.empty() || s[st.top()] != s[i]){
b = 0;
break;
}
st.pop();
}
}
if(st.size()) b = 0;
if(b){
string ans = "";
for(int i = n - 1; i >= 0; i--){
if((1 << i) & mask) ans += '(';
else ans += ')';
}
cout << ans << '\n';
return;
}
}
cout << "-1\n";
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
4 |
Incorrect |
112 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 |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
3 ms |
336 KB |
Output is correct |
4 |
Incorrect |
112 ms |
336 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |