#include <bits/stdc++.h>
using namespace std;
int const N=1e5+5;
struct node
{
char ch;
map<char,node*> mp;
set<pair<int,node*>> adj;
int dep=1;
int cnt=0;
};
node* root;
void add(){
string s;
cin>>s;
int i=0;
node* cur=root;
while(i<int(s.length())){
if(cur->mp[s[i]]==NULL){
cur->mp[s[i]]=new node();
cur->mp[s[i]]->ch=s[i];
}
cur=cur->mp[s[i]];
i++;
}
cur->cnt++;
}
int dep_set(node* rt){
for(auto i:rt->mp){
rt->dep=max(rt->dep,dep_set(i.second)+1);
rt->adj.insert({i.second->dep,i.second});
}
return rt->dep;
}
vector<char> ans;
void dfs1(node* rt){
for (int i = 0; i < rt->cnt; ++i)
ans.push_back('P');
for(auto i:rt->adj){
ans.push_back(i.second->ch);
dfs1(i.second);
ans.push_back('-');
}
}
int main(){
int t;
cin>>t;
root=new node();
for (int i = 0; i < t; ++i)
add();
dep_set(root);
dfs1(root);
int sz=ans.size();
while(sz>0&&ans[sz-1]=='-'){
ans.pop_back();
sz--;
}
printf("%d",sz);
for(char i:ans)
printf("%c",i);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Expected integer, but "20tptttykduyvxjbzhqupP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Expected integer, but "142nP-yerxP----xxvebmcP-------...----------labfaryosskugbkiuffdP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Expected integer, but "201hjxgqkP------iupqiqP------r...------------wPfxlmwfirlgbdevjdP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
340 KB |
Expected integer, but "290tdsP---qgjP---lbuaP---twxfb...--------------xomsgennpdlurnmvP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Expected integer, but "1193wuyP---jPuegP---chgP---ogd...vegnwxeP----------eynorwrbizaiP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2004 KB |
Expected integer, but "14145vPlscbP----mhkbP----izfrP...lP-----------cclviwgdudcybahuwP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
9 ms |
6584 KB |
Expected integer, but "52541rPnP-aPpbwphP------baP-fa...-------------zuknicjtukmwmlddzP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
25 ms |
16456 KB |
Expected integer, but "135477xPccvP--vlP--iobP---ylmw...--------------gPkwzakqubhstcdqP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
79 ms |
41092 KB |
Expected integer, but "337528vPaPjP-dojzP----xtsP--xe...----xPtdkP---uwnpkeulxgrymykjsP" found |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
86 ms |
31980 KB |
Expected integer, but "273585pPsPhpnP---zkccP---jqrP-...sP----------jbfbP---jtearnhdjeP" found |
2 |
Halted |
0 ms |
0 KB |
- |