# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259431 |
2020-08-07T19:44:35 Z |
doowey |
Match (CEOI16_match) |
C++14 |
|
72 ms |
70136 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int AL = 26;
const int N = (int)1e5 + 10;
const int T = (int)1e5 + 10;
int nx[T][AL];
char fs[N];
int shis[N];
int par[N];
int cnt = 1;
int root[N];
vector<int> P[T][AL];
char sol[N];
void compute(int l, int r){
if(l > r) return;
int ix = root[l - 1];
int cv = shis[l];
int it = upper_bound(P[ix][cv].begin(), P[ix][cv].end(), r) - P[ix][cv].begin();
it -- ;
int id = P[ix][cv][it];
if(id > l && id <= r){
sol[l]='(';
sol[id]=')';
compute(l+1, id-1);
compute(id+1, r);
}
else{
cout << "bad\n";
return;
}
}
int main(){
fastIO;
string t;
cin >> t;
int n = t.size();
char f;
int id;
fs[1] = '#';
root[0] = 1;
for(int i = 1; i <= n; i ++ ){
f = t[i - 1];
id = f - 'a';
shis[i]=id;
if(f == fs[root[i - 1]]){
root[i] = par[root[i-1]];
}
else{
root[i] = root[i - 1];
if(nx[root[i]][id] == 0){
nx[root[i]][id] = ++cnt;
par[cnt] = root[i];
fs[cnt] = f;
}
root[i] = nx[root[i]][id];
}
P[root[i]][id].push_back(i);
}
if(root[n] != 1){
cout << "-1\n";
return 0;
}
compute(1, n);
for(int i = 1; i <= n; i ++ )
cout << sol[i];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
61440 KB |
Output is correct |
2 |
Correct |
36 ms |
61440 KB |
Output is correct |
3 |
Correct |
37 ms |
61440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
61440 KB |
Output is correct |
2 |
Correct |
36 ms |
61440 KB |
Output is correct |
3 |
Correct |
37 ms |
61440 KB |
Output is correct |
4 |
Correct |
36 ms |
61432 KB |
Output is correct |
5 |
Correct |
36 ms |
61560 KB |
Output is correct |
6 |
Correct |
36 ms |
61440 KB |
Output is correct |
7 |
Correct |
37 ms |
61560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
61440 KB |
Output is correct |
2 |
Correct |
36 ms |
61440 KB |
Output is correct |
3 |
Correct |
37 ms |
61440 KB |
Output is correct |
4 |
Correct |
36 ms |
61432 KB |
Output is correct |
5 |
Correct |
36 ms |
61560 KB |
Output is correct |
6 |
Correct |
36 ms |
61440 KB |
Output is correct |
7 |
Correct |
37 ms |
61560 KB |
Output is correct |
8 |
Correct |
38 ms |
61816 KB |
Output is correct |
9 |
Correct |
38 ms |
61944 KB |
Output is correct |
10 |
Correct |
38 ms |
62072 KB |
Output is correct |
11 |
Correct |
39 ms |
62072 KB |
Output is correct |
12 |
Correct |
52 ms |
67320 KB |
Output is correct |
13 |
Correct |
54 ms |
68088 KB |
Output is correct |
14 |
Correct |
55 ms |
68480 KB |
Output is correct |
15 |
Correct |
43 ms |
63872 KB |
Output is correct |
16 |
Correct |
44 ms |
63864 KB |
Output is correct |
17 |
Correct |
54 ms |
67064 KB |
Output is correct |
18 |
Correct |
46 ms |
63480 KB |
Output is correct |
19 |
Correct |
63 ms |
70136 KB |
Output is correct |
20 |
Correct |
53 ms |
67576 KB |
Output is correct |
21 |
Correct |
72 ms |
70136 KB |
Output is correct |