#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:x) cout << it << " "; cout << #y << endl;
typedef pair<int,int>pii;
typedef pair<pii,pii>pi2;
pii sz2[30];
void solve(){
int n;
cin >> n;
string arr[n];
int sz=100;
for(int x=0;x<n;x++){
cin >> arr[x];
sz=min(sz,(int)arr[x].length());
}
vector<char>ans;
int ptr=-1;
for(int x=0;x<sz;x++){
bool amos=true;
for(int y=1;y<n;y++){
if(arr[y][x]!=arr[y-1][x]) amos=false;
}
if(amos) ans.push_back(arr[0][x]);
else break;
ptr=x;
}
ptr++;
//remove prefix
vector<string>storage[30];
for(int x=0;x<n;x++){
arr[x]=arr[x].substr(ptr,(int)arr[x].length()-ptr);
if((int)arr[x].length()==0) continue;
int index=arr[x][0]-'a';
storage[index].push_back(arr[x]);
sz2[index].first=max(sz2[index].first,(int)arr[x].length());
}
for(int x=0;x<30;x++){
sz2[x].second=x;
sort(storage[x].begin(),storage[x].end());
}
sort(sz2,sz2+30);
string last="";
for(int x=0;x<30;x++){
int index=sz2[x].second;
for(auto it:storage[index]){
int target=-1;
int mini=min((int)it.length(),(int)last.length());
for(int y=0;y<mini;y++){
if(it[y]==last[y]) target=y;
else break;
}
while((int)last.length()>target+1){
ans.push_back('-');
last.pop_back();
}
for(int y=target+1;y<(int)it.length();y++){
ans.push_back(it[y]);
}
ans.push_back('P');
last=it;
}
}
cout << ans.size() << "\n";
for(auto it:ans){
cout << it << "\n";
}
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("in.txt", "r", stdin);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
856 KB |
Output is correct |
2 |
Incorrect |
7 ms |
1368 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
1784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
30 ms |
3268 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
17 ms |
3284 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |