#include "bits/stdc++.h"
using namespace std;
#ifndef LOCAL
#define debug(...) 86
#endif
const int maxN = 1e5 + 5;
const int maxC = 26;
struct node {
int end;
node *child[maxC];
node() {
end = 0;
for (int i = 0; i < maxC; ++i) child[i] = NULL;
}
};
int nxt;
node nodes[maxN];
node *newnode() {
return &nodes[nxt++];
}
vector<char> res;
struct trie {
node *root;
trie() {
root = newnode();
}
void insert(node *n, string &s, int pos) {
if (pos == (int)s.size()) {
n->end = 1;
return;
}
if (!n->child[s[pos] - 'a']) {
n->child[s[pos] - 'a'] = newnode();
}
insert(n->child[s[pos] - 'a'], s, pos + 1);
}
void solve(node *n) {
if (n->end) res.emplace_back('P');
for (int i = 0; i < maxC; ++i) {
if (!n->child[i]) continue;
res.emplace_back(char(i + 'a'));
solve(n->child[i]);
}
res.emplace_back('-');
}
};
trie T;
int N;
int main() {
ios::sync_with_stdio(0), cin.tie(0);
cin >> N;
for (int i = 0; i < N; ++i) {
string s; cin >> s;
T.insert(T.root, s, 0);
}
T.solve(T.root);
cout << (int)res.size() << '\n';
while (res.back() == '-') res.pop_back();
for (auto &x : res) cout << x << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
21444 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
21456 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
21460 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
9 ms |
21460 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
11 ms |
21452 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
12 ms |
21460 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
16 ms |
21708 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
27 ms |
21988 KB |
Line "" doesn't correspond to pattern "[a-z\-P]{1}" |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
36 ms |
43432 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
35 ms |
43440 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |