#include <bits/stdc++.h>
// mrrrow meeow :3
// go play vivid/stasis now! https://vividstasis.gay
#define fo(i, a, b) for (auto i = (a); i < (b); i++)
#define of(i, a, b) for (auto i = (b); i-- > (a);)
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define be(a) a.begin(), a.end()
using namespace std;
int ____init = [] {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
return 0;
}();
int alphabets[20][26];
int main() {
int n;
cin >> n;
vector<string> a(n);
string maxs;
fo(i, 0, n) cin >> a[i], maxs = a[i].size() > maxs.size() ? a[i] : maxs;
fo(i, 0, maxs.size()) {
fo(j, 0, 26) alphabets[i][j] = j;
swap(alphabets[i][maxs[i] - 'a'], alphabets[i][25]);
}
sort(be(a), [](string a, string b) {
fo(i, 0, min(a.size(), b.size())) {
if (alphabets[i][a[i] - 'a'] < alphabets[i][b[i] - 'a']) return true;
if (alphabets[i][a[i] - 'a'] > alphabets[i][b[i] - 'a']) return false;
}
return a.size() < b.size();
});
string res;
string curr;
for (string i : a) {
while (curr.size() > i.size()) res.pb('-'), curr.pob();
int j = 0;
while (j < curr.size() && curr[j] == i[j]) j++;
of(_, j, curr.size()) res.pb('-'), curr.pob();
while (curr.size() < i.size()) res.pb(i[curr.size()]), curr.pb(i[curr.size()]);
res.pb('P');
}
cout << res.size() << endl;
for (char i : res) cout << i << endl;
}
# | 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... |