//Coded by Chirath Nirodha
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define P push
#define I insert
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const string abc="abcdefghijklmnopqrstuvwxyz";
const string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const ll mod=1e9+7;
inline void io(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
string s;int last[100000][26];
string ans;
void rec(int l,int r){
if(l>r)return;
int x=s[l]-'a';
if(last[r][x]<=l){
exit(0);
}
ans[l]='(';
ans[last[r][x]]=')';
if(r-l==1)return;
rec(l+1,last[r][x]-1);
rec(last[r][x]+1,r);
}
void solve(){
io();
cin>>s;
ans=s;
int n=s.size();
for(int i=0;i<n;i++){
for(int j=0;j<26;j++){
int x=s[i]-'a';
if(x==j)last[i][j]=i;
else if(i>0 && last[i-1][x]>0)last[i][j]=last[last[i-1][x]-1][j];
else last[i][j]=-1;
}
}
rec(0,n-1);
cout<<ans<<endl;
}
int main(){
io();
solve();
//int t;cin>>t;for(int i=0;i<t;i++)solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |