Submission #62607

#TimeUsernameProblemLanguageResultExecution timeMemory
62607tmwilliamlin168Match (CEOI16_match)C++14
0 / 100
3 ms356 KiB
#include <bits/stdc++.h> using namespace std; string s, a; int n, st[100000], sti; vector<int> occ[26]; inline void fk() { cout << -1; exit(0); } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s; n=s.size(); for(int i=0; i<n; ++i) occ[s[i]-'a'].push_back(i); a.resize(n); for(int i=0; i<26; ++i) { if(occ[i].size()&1) fk(); for(int j=0; j<(int)occ[i].size()-1-j; ++j) a[occ[i][j]]='(', a[occ[i][occ[i].size()-1-j]]=')'; } for(int i=0; i<n; ++i) { if(a[i]==')'&&(!sti||s[st[--sti]]!=s[i])) fk(); else if(a[i]=='(') st[sti++]=i; } cout << a; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...