#include<bits/stdc++.h>
using namespace std;
#define int long long
int nbMots,rep,plusLong;
string maxiMot;
vector<string> motTri;
int commun(string a,string b) {
int ans=0;
while (ans<(int)a.size() and ans<(int)b.size() and a[ans]==b[ans]) {
ans++;
}
return ans;
}
void afficher(string a,int deb) {
for (int i=deb;i<(int)a.size();i++) {
cout<<a[i]<<"\n";
}
cout<<"P"<<"\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbMots;
string nouvMot;
for (int i=0;i<nbMots;i++) {
cin>>nouvMot;
motTri.push_back(nouvMot);
}
sort(motTri.begin(),motTri.end());
for (int i=0;i<nbMots;i++) {
rep+=2*motTri[i].size();
if ((int)motTri[i].size()>=plusLong) {
plusLong=motTri[i].size();
maxiMot=motTri[i];
}
}
for (int i=0;i<nbMots-1;i++) {
rep-=2*commun(motTri[i],motTri[i+1]);
}
rep-=plusLong;
rep+=nbMots;
cout<<rep<<"\n";
sort(motTri.begin(),motTri.end(),[&] (string a,string b) {
if (commun(a,maxiMot)!=commun(b,maxiMot)) {
return commun(a,maxiMot)<commun(b,maxiMot);
}
return a<b;
});
afficher(motTri[0],0);
int deb;
for (int i=1;i<nbMots;i++) {
deb=commun(motTri[i-1],motTri[i]);
for (int j=(int)motTri[i-1].size()-1;j>=deb;j--) {
cout<<"-"<<"\n";
}
afficher(motTri[i],deb);
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
600 KB |
Output is correct |
2 |
Correct |
18 ms |
1020 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
18 ms |
1244 KB |
Output is correct |
2 |
Correct |
24 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2032 KB |
Output is correct |
2 |
Correct |
77 ms |
3576 KB |
Output is correct |
3 |
Correct |
68 ms |
2824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
41 ms |
2000 KB |
Output is correct |
2 |
Correct |
87 ms |
4336 KB |
Output is correct |
3 |
Correct |
79 ms |
3268 KB |
Output is correct |
4 |
Correct |
86 ms |
4168 KB |
Output is correct |