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;
typedef long long ll;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<string> s(n);
array<int,2> m={0,0};
for(int i=0;i<n;i++)
{
cin >> s[i];
m=max(m,{int(s[i].size()),i});
}
vector<pair<int,string>> v(n);
for(int i=0;i<n;i++)
{
int c=-1;
while(c+1<(int)s[i].size()&&s[i][c+1]==s[m[1]][c+1]) c++;
v[i]={c+1,s[i]};
}
sort(v.begin(),v.end());
string now;
string res;
for(auto [c,t]:v)
{
int len=-1;
while(len+1<int(min(now.size(),t.size()))&&now[len+1]==t[len+1]) len++;
res+=string((int)now.size()-(len+1),'-');
for(int i=len+1;i<(int)t.size();i++) res+=t[i];
res+='P';
now=t;
}
cout << res.size() << "\n";
for(char c:res) cout << c << "\n";
return 0;
}
# | 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... |