#include <bits/stdc++.h>
using namespace std;
int main() {
int q;
cin >> q;
vector<string>word_list;
while (q--) {
string s;
cin >> s;
word_list.push_back(s);
}
sort(word_list.begin(),word_list.end(),greater<string>());
deque<char>word;
vector<char>ans;
for (auto &a : word_list) {
while (!word.empty()) {
if (word.back() == a[word.size()-1]) {
for (int i=word.size(); i<a.length(); i++) {
ans.push_back(a[i]);
word.push_back(a[i]);
}
ans.push_back('P');
break;
}
word.pop_back();
ans.push_back('-');
}
if (word.empty()) {
for (auto &c : a) {
ans.push_back(c);
word.push_back(c);
}
ans.push_back('P');
continue;
}
}
cout << ans.size()-1 << "\n";
for (auto &a : ans) cout << a << " \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... |