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>
#define ll long long
using namespace std;
string maxi="";
int pref(string a) {
int cnt=0;
while (a[cnt] == maxi[cnt]) {
cnt++;
}
return cnt;
}
static bool cmp(string&a,string&b) {
int x=pref(a);
int y=pref(b);
if (a == maxi) {
return false;
}
if (b == maxi) {
return true;
}
if (x != y) {
return x<y;
}
return a.size() < b.size();
}
int main() {
ll n;
cin >> n;
vector<string> p(n);
for (int i=0;i<n;i++) {
cin >> p[i];
if (p[i].size() > maxi.size()) {
maxi = p[i];
}
}
sort(p.begin(),p.end(),cmp);
string curr="";
string ans="";
for (int i=0;i<n;i++) {
while (curr.size() != 0 && curr != p[i].substr(0,curr.size())) {
ans+="-";
curr.pop_back();
}
ans+=p[i].substr(curr.size(),p[i].size()-curr.size());
curr=p[i];
ans+="P";
}
n = ans.size();
cout << n<<'\n';
for (int i=0;i<n;i++) {
cout << ans[i] <<'\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... |