Submission #1117651

#TimeUsernameProblemLanguageResultExecution timeMemory
1117651vjudge1괄호 문자열 (CEOI16_match)C++17
10 / 100
1 ms336 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define inf 0x3F3F3F3F3F3F3F3F const int MXN = 3e6 + 5; const int mod = 998244353; int n; string s, res; vector<int> st; int fl[26], fcur[26]; void fix(int ind) { fcur[s[ind] - 'a'] -= 2; res[ind] = ')'; while (!st.empty() && s[st.back()] != s[ind]) { int nw = st.back(); st.pop_back(); fix(nw); } if (st.empty()) { cout << -1 << '\n'; exit(0); } st.pop_back(); } void _() { cin >> s; n = s.length(); if (n & 1) { cout << -1 << '\n'; return; } for (char &ch : s) fl[ch - 'a']++; res = s; for (int i = 0; i < n; i++) { fcur[s[i] - 'a']++, fl[s[i] - 'a']--; if (fl[s[i] - 'a'] < fcur[s[i] - 'a']) fix(i); else res[i] = '(', st.push_back(i); } cout << res << '\n'; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while (t--) _(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...