This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
using namespace std;
const int maxn = 25005;
int n;
string del;
struct trie {
int total_nodes;
struct node {
node *child[26];
bool exist;
node() {
exist = 0;
for(int i = 0; i < 26; ++i) {
child[i] = nullptr;
}
}
} *root;
trie() {
total_nodes = 0;
root = new node();
}
void add(string &s) {
node *p = root;
for(int i = 0; i < (int)s.size(); ++i) {
int c = s[i] - 'a';
if(p->child[c] == nullptr) {
p->child[c] = new node();
++total_nodes;
}
p = p->child[c];
}
p->exist = 1;
}
void dfs(int depth, node *p) {
for(int i = 0; i < 26; ++i) {
if(p->child[i] == nullptr || i == del[depth] - 'a') continue;
cout << char(i + 'a') << '\n';
dfs(depth + 1, p->child[i]);
cout << '-' << '\n';
}
if(depth < (int)del.size() and p->child[del[depth] - 'a'] != nullptr) {
cout << del[depth] << '\n';
dfs(depth + 1, p->child[del[depth] - 'a']);
// cout << '-' << '\n';
}
if(p->exist) {
cout << 'P' << '\n';
return;
}
}
void dfs() {
dfs(0, root);
}
} t;
void solve() {
cin >> n;
string s;
for(int i = 1; i <= n; ++i) {
cin >> s;
t.add(s);
if((int)s.size() > (int)del.size()) {
del = s;
}
}
cout << t.total_nodes * 2 + n - (int)del.size() << '\n';
t.dfs();
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
solve();
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |