제출 #388772

#제출 시각아이디문제언어결과실행 시간메모리
388772Ahmad_HasanMatch (CEOI16_match)C++17
10 / 100
1 ms452 KiB
#include <bits/stdc++.h> using namespace std; int prf[26][(int)1e5+5]; string out; string s; int n; int f=0; bool check(int l,int r){ if(l>r)return true; for(int i=0;i<26;i++){ if((prf[i][r+1]-prf[i][l])&1)return false; } return true; } void slv(int l=0,int r=n-1){ if(l>r)return; int sf=0; int i=0; for(i=r;i>l;i--){ if(s[i]==s[l]&&check(l+1,i-1)){ sf=1; out[l]='('; out[i]=')'; slv(l+1,i-1); break; } } if(!sf){ f=1; return; } slv(i+1,r); } int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>s; n=s.size(); for(int i=0;i<26;i++)prf[i][0]=0; for(int i=0;i<n;i++){ for(int j=0;j<26;j++){ prf[j][i+1]=prf[j][i]+(j==s[i]-'a'); } } out=s; slv(); if(f) cout<<-1<<'\n'; else cout << out << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...