# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
844950 |
2023-09-06T09:47:06 Z |
1bin |
Match (CEOI16_match) |
C++14 |
|
1 ms |
348 KB |
#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 |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |