# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
826601 |
2023-08-15T17:38:49 Z |
NK_ |
Match (CEOI16_match) |
C++17 |
|
1 ms |
340 KB |
// Success consists of going from failure to failure without loss of enthusiasm
#include <bits/stdc++.h>
using namespace std;
#define nl '\n'
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define sz(x) int(x.size())
template<class T> using V = vector<T>;
using vi = V<int>;
using ll = long long;
using pl = pair<ll, ll>;
using vl = V<ll>;
int main() {
cin.tie(0)->sync_with_stdio(0);
string S; cin >> S;
int N = sz(S);
string ans(N, '-');
V<map<int, vector<int>>> oc(26);
vi P = {0};
for(int i = 0; i < N; i++) {
int c = S[i] - 'a'; P.pb(P.back() ^ (1 << c));
// cout << i << " " << S[i] << " " << P.back() << endl;
oc[c][P.back()].pb(i);
}
function<void(int, int)> dnc = [&](int l, int r) {
if (l > r) return;
int lc = S[l] - 'a';
// cout << l << " " << r << endl;
auto it = upper_bound(begin(oc[lc][P[l]]), end(oc[lc][P[l]]), r);
if (it == begin(oc[lc][P[l]])) {
cout << -1 << nl;
exit(0-0);
}
int m = *prev(it);
if (l > m) {
cout << -1 << nl;
exit(0-0);
}
ans[l] = '(', ans[m] = ')';
dnc(l + 1, m - 1); dnc(m + 1, r);
};
dnc(0, N - 1);
cout << ans << nl;
exit(0-0);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |