#include <bits/stdc++.h>
using namespace std;
#define LCBorz ios_base::sync_with_stdio(false); cin.tie(0);
#define int long long
#define all(x) x.begin(), x.end()
#define endl '\n'
const int N=200005;
const int INF=1e18;
vector<int> a[26];
vector<int> v;
string ans;
void solve(int l,int r){
if(l>=r)return;
auto it=--lower_bound(all(a[v[l]]),r);
if(*it<=l){
cout<<-1<<endl;
exit(0);
}
ans[l]='(';
ans[*it]=')';
solve(l+1,*it);
solve(*it+1,r);
}
int32_t main() {
LCBorz;
string s;cin>>s;
int n=s.size();
v.resize(n);
ans.assign(n,'0');
for(int i=0;i<n;i++){
int p=s[i]-'a';
v[i]=p;
a[p].push_back(i);
}
solve(0,n);
cout<<ans<<endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |