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;
string c;
bool cmp(string &a,string &b)
{
int cnt1=a.size(),cnt2=b.size();
for(int i=0;i<(int)a.size();i++)
if(a[i]!=c[i])
cnt1=i;
for(int i=0;i<(int)b.size();i++)
if(b[i]!=c[i])
cnt2=i;
if(cnt1==cnt2) return a<b;
return cnt1<cnt2;
}
int main()
{
int n;
int mx=0;
cin>>n;
string s[n];
for(int i=0;i<n;i++)
{
cin>>s[i];
if((int)s[i].size()>mx||((int)s[i].size()==mx&&s[i]>c))
mx=(int)s[i].size(),c=s[i];
}
vector<char>ans;
sort(s,s+n,cmp);
for(int i=0;i<(int)s[0].size();i++)
ans.push_back(s[0][i]);
ans.push_back('p');
for(int i=1;i<n;i++)
{
if(s[i-1].size()>s[i].size())
for(int i=0;i<(int)s[i-1].size()-(int)s[i].size();i++)
ans.push_back('-');
int sz=min((int)s[i-1].size(),(int)s[i].size());
int k=0;
for(;k<sz;k++)
if(s[i-1][k]!=s[i][k])
break;
k--;
for(int j=k;j<sz-1;j++)
ans.push_back('-');
k++;
for(;k<(int)s[i].size();k++)
ans.push_back(s[i][k]);
ans.push_back('P');
}
cout<<ans.size()<<endl;
for(auto i:ans)
cout<<i<<'\n';
}
# | 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... |