제출 #1117596

#제출 시각아이디문제언어결과실행 시간메모리
1117596AtabayRajabli괄호 문자열 (CEOI16_match)C++17
0 / 100
1 ms336 KiB
#include <bits/stdc++.h> #define all(v) v.begin(), v.end() #define int long long using namespace std; const int sz = 1e5 + 5; int n, f[26], o[26]; string s, t = ""; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> s; n = s.size(); for(char c : s) f[c - 'a']++; bool ok = 0; for(int i = 0; i < 26; i++) ok |= (f[i] & 1); if(ok) { cout << -1; return 0; } for(int i = 0; i < n; i++) { int l = s[i] - 'a'; if(f[l] > o[l]) { t += '('; o[l]++; f[l]--; } else { t += ')'; o[l]--; f[l]--; } } ok = 1; stack<int> st; for(int i = 0; i < n; i++) { if(t[i] == '(') st.push(i); else { ok &= s[st.top()] == s[i]; st.pop(); } } if(!ok) t = "-1"; cout << t; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...