This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |