# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
717699 |
2023-04-02T10:59:56 Z |
stevancv |
Match (CEOI16_match) |
C++14 |
|
19 ms |
11712 KB |
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define sp ' '
#define en '\n'
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
using namespace std;
const int N = 1e5 + 2;
const int inf = 1e9;
int gde[N][26];
int ans[N];
string s;
void Resi(int l, int r) {
if (l > r) return;
int mid = gde[r][s[l] - 'a'];
ans[mid] = 1;
Resi(l + 1, mid - 1);
Resi(mid + 1, r);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> s;
int n = s.size();
stack<char> stk;
for (int i = 0; i < n; i++) {
if (!stk.empty() && stk.top() == s[i]) stk.pop();
else stk.push(s[i]);
}
if (!stk.empty()) {
cout << -1 << en;
return 0;
}
for (int i = 0; i < 26 * n; i++) gde[i / 26][i % 26] = -1;
gde[0][s[0] - 'a'] = 0;
for (int i = 1; i < n; i++) {
for (int j = 0; j < 26; j++) {
if (s[i] - 'a' == j) gde[i][j] = i;
else if (gde[i - 1][s[i] - 'a'] > 0) gde[i][j] = gde[gde[i - 1][s[i] - 'a'] - 1][j];
}
}
Resi(0, n - 1);
for (int i = 0; i < n; i++) {
if (ans[i] == 0) cout << '(';
else cout << ')';
}
cout << en;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
456 KB |
Output is correct |
8 |
Correct |
2 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
1108 KB |
Output is correct |
10 |
Correct |
2 ms |
1108 KB |
Output is correct |
11 |
Correct |
2 ms |
1108 KB |
Output is correct |
12 |
Correct |
11 ms |
7124 KB |
Output is correct |
13 |
Correct |
11 ms |
7764 KB |
Output is correct |
14 |
Correct |
12 ms |
8444 KB |
Output is correct |
15 |
Correct |
13 ms |
9808 KB |
Output is correct |
16 |
Correct |
14 ms |
9624 KB |
Output is correct |
17 |
Correct |
14 ms |
10288 KB |
Output is correct |
18 |
Correct |
17 ms |
10452 KB |
Output is correct |
19 |
Correct |
19 ms |
11056 KB |
Output is correct |
20 |
Correct |
11 ms |
7252 KB |
Output is correct |
21 |
Correct |
18 ms |
11712 KB |
Output is correct |