Submission #940177

#TimeUsernameProblemLanguageResultExecution timeMemory
940177thinknoexitMatch (CEOI16_match)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int a[100100]; vector<int> pos[26]; int main() { cin.tie(nullptr)->sync_with_stdio(false); string s; cin >> s; int n = s.size(); for (int i = 0;i < n;i++) { pos[s[i] - 'a'].push_back(i); } for (int i = 0;i < 26;i++) { int m = pos[i].size(); if (m & 1) { cout << -1; return 0; } for (int j = 0;j < m / 2;j++) { a[pos[i][j]] = -1; } for (int j = m / 2;j < m;j++) { a[pos[i][j]] = 1; } } stack<char> st; for (int i = 0;i < n;i++) { if (a[i] == -1) { st.push(s[i]); } else { if (st.empty()) { cout << -1; return 0; } if (st.top() != s[i]) { cout << -1; return 0; } st.pop(); } } for (int i = 0;i < n;i++) { cout << "()"[a[i] == 1]; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...