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;
#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;
void solve(){
int n;
cin >> n;
string arr[n];
int sz=-1;
string maxi="";
for(int x=0;x<n;x++){
cin >> arr[x];
if((int)arr[x].length()>sz){
sz=(int)arr[x].length();
maxi=arr[x];
}
}
vector<string>v[30];
for(int x=0;x<n;x++){
int mini=min((int)arr[x].length(),sz);
int counter=0;
for(int y=0;y<mini;y++){
if(arr[x][y]==maxi[y]) counter++;
else break;
}
v[counter].push_back(arr[x]);
}
for(int x=0;x<30;x++) sort(v[x].begin(),v[x].end());
string last="";
vector<char>ans;
for(int x=0;x<30;x++){
for(auto it:v[x]){
int mini=min((int)it.length(),(int)last.length());
int target=-1;
for(int y=0;y<mini;y++){
if(it[y]==last[y]) target++;
else break;
}
while((int)last.size()>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 |
---|
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... |