#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef unsigned int uint;
typedef pair<int, int> pii;
//mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
#define pb push_back
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define TC int __TC__; cin >> __TC__; while(__TC__--)
#define ar array
const int INF = 1e9 + 7, N = 1e6;
int trie[N][26], p=0, last[N], n, sum=0, d[N];
string s,ans;
void insert(int i, int rt){
if(i == s.size()){
++last[rt];
return;
}
if(!trie[rt][s[i]-'a']) trie[rt][s[i]-'a'] = ++p;
insert(i + 1, trie[rt][s[i]-'a']);
}
void dfs1(int u){
bool leaf = 1;
for(int i = 0; i < 26; ++i){
int v = trie[u][i];
if(v){
leaf=0;
dfs1(v);
d[u] = max(d[u], d[v]+1);
}
}
if(leaf) d[u] = 1;
}
void dfs(int u){
for(int i = 0; i < last[u]; ++i){
ans += 'P';
}
sum -= last[u];
if(sum==0){
cout << ans.size() <<'\n';
for(char c : ans){
cout << c << '\n';
}
exit(0);
}
int deepest = 0;
for(int i = 0; i < 26; ++i){
if(trie[u][i] && d[trie[u][i]] > d[trie[u][deepest]]){
deepest = i;
}
}
for(int i= 0; i < 26; ++i){
if(trie[u][i] && i != deepest){
debug() << exp(u) exp(i);
ans += (char)('a'+i);
dfs(trie[u][i]);
ans+='-';
}
}
if(trie[u][deepest]){
ans+=(char)('a'+deepest);
dfs(trie[u][deepest]);
ans+='-';
}
}
int main()
{
FAST;
cin >> n;
for(int i = 0; i < n; ++i){
cin >> s;
insert(0, 0);
}
sum = n;
dfs1(0);
d[0] = -INF;
dfs(0);
return 0;
}
Compilation message
printer.cpp: In function 'void insert(int, int)':
printer.cpp:21:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
21 | if(i == s.size()){
| ~~^~~~~~~~~~~
printer.cpp: In function 'void dfs(int)':
printer.cpp:68:4: error: 'debug' was not declared in this scope
68 | debug() << exp(u) exp(i);
| ^~~~~