Submission #1173535

#TimeUsernameProblemLanguageResultExecution timeMemory
1173535thinknoexitMatch (CEOI16_match)C++17
0 / 100
0 ms324 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int a[100100], qs[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 + 1); } 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; } } for (int i = 1;i <= n;i++) { qs[i] = qs[i - 1] + a[i]; } for (int i = 0;i < 26;i++) { int m = pos[i].size(); for (int j = 0;j < m - 1;j++) { if (qs[pos[i][j + 1] - 1] - qs[pos[i][j]] != 0) { cout << "-1\n"; return 0; } } } for (int i = 1;i <= n;i++) { cout << "()"[a[i] == 1]; } return 0; } /* if between each character contain valid bracket sequence EX. a ... a ... a ... a if every ... is valid bracket sequence you can construct the bracket whenever you want */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...