#pragma GCC optimize ("O3")
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define pb push_back
#define iospeed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int main()
{
iospeed
string s;
cin >> s;
ll n = (ll)(s.size()), i, j, k;
string res = "z", res2 = "z";
for(i = 0; i < (1 << n); i++)
{
ll pref[n+5];
pref[0] = 0;
string str = "";
bool ok = true;
for(j = 0; j < n; j++)
{
pref[j+1] = pref[j];
if((i >> j) & 1){
str += ")";
pref[j+1]--;
}
else{
str += "(";
pref[j+1]++;
}
if(pref[j+1] < 0)
{
ok = false;
break;
}
}
if(!ok)
continue;
for(j = 1; j <= n; j++)
{
for(k = j + 1; k <= n; k++)
{
if(pref[k] - pref[j-1] == 0 && str[j-1] == '(' && str[k-1] == ')')
{
if(k == j + 1 || pref[k-1] - pref[j] == 0){
if(s[k-1] != s[j-1])
{
ok = false;
break;
}
}
}
}
}
if(ok && pref[n] == 0)
res = min(res, str);
}
if(res == res2)
cout << "-1\n";
else
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |