Submission #844950

#TimeUsernameProblemLanguageResultExecution timeMemory
8449501binMatch (CEOI16_match)C++14
0 / 100
1 ms348 KiB
#include<bits/stdc++.h> using namespace std; #define all(v) v.begin(), v.end() typedef long long ll; const int NMAX = 1e5 + 5; int n, a[NMAX], p[NMAX], t, chk[NMAX]; string s; map<int, deque<int>> mp[26]; int main(void){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s; n = s.size(); for(int i = 0; i < n; i++) a[i] = s[i] - 'a'; for(int i = 0; i < n; i++){ t ^= (1 << a[i]); p[i] = t; mp[a[i]][t].emplace_back(i); } for(int i = 0; i < n; i++){ if(chk[i]) continue; t = p[i] ^ (1 << a[i]); if(mp[a[i]][t].empty()) { cout << -1; return 0; } int j = mp[a[i]][t].back(); chk[i] = 1; chk[j] = -1; mp[a[i]][p[i]].pop_front(); mp[a[i]][t].pop_back(); } for(int i = 0; i < n; i++) cout << (chk[i] == 1 ? '(' : ')'); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...