/*input
3
print
the
poem
*/
#include <bits/stdc++.h>
using namespace std;
namespace my_template {
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef vector<pi> vpi;
typedef vector<vpi> vpii;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
typedef vector<pd> vpd;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef std::string str;
typedef std::vector<str> vs;
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
const ld PI = 3.14159265358979323846264338327950288419716939937510582097494L;
template<typename T>
pair<T, T> operator+(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x + b.x, a.y + b.y); }
template<typename T>
pair<T, T> operator-(const pair<T, T> &a, const pair<T, T> &b) { return pair<T, T>(a.x - b.x, a.y - b.y); }
template<typename T>
T operator*(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.x + a.y * b.y); }
template<typename T>
T operator^(const pair<T, T> &a, const pair<T, T> &b) { return (a.x * b.y - a.y * b.x); }
template<typename T>
void print(vector<T> vec, string name = "") {
cout << name;
for (auto u : vec)
cout << u << ' ';
cout << '\n';
}
}
using namespace my_template;
const int MOD = 1000000007;
const ll INF = std::numeric_limits<ll>::max();
const int MX = 100101;
vector<char> ats;
string curr(MX, '-');
str did = "";
int j = 1;
void del() {
assert(j > 0);
ats.emplace_back('-');
j--;
}
void add(char ch) {
curr[j++] = ch;
ats.emplace_back(ch);
}
void print() {
ats.emplace_back('P');
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N;
cin >> N;
vs sk(N);
for (int i = 0; i < N; ++i) {
cin >> sk[i];
sk[i].insert(sk[i].begin(), '-');
if (sk[i].size() > did.size())
did = sk[i];
}
sort(sk.begin(), sk.end(), [](const str & a, const str & b) {
int k1 = 0;
int k2 = 0;
while (k1 + 1 < (int)did.size() and a[k1 + 1] == did[k1 + 1]) k1++;
while (k2 + 1 < (int)did.size() and b[k2 + 1] == did[k2 + 1]) k2++;
if (k1 != k2) return k1 < k2;
else return a < b;
});
for (int i = 0; i < N; ++i)
{
int k = 0;
str s = sk[i];
while (k + 1 < (int)s.size() and s[k + 1] == curr[k + 1]) {
k++;
}
while (j - 1 > k) {
del();
}
// printf("k = %d, j = %d,ssz = %d\n", k, j, (int)s.size());
for (int r = j; r < (int)s.size(); ++r)
{
add(s[r]);
}
print();
}
// printf("SUCCESS\n");
printf("%d\n", (int)ats.size());
for (int i = 0; i < (int)ats.size(); ++i)
{
printf("%c\n", ats[i]);
}
}
/* Look for:
* special cases (n=1?)
* overflow (ll vs int?)
* the exact constraints (multiple sets are too slow for n=10^6 :( )
* array bounds
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
768 KB |
Output is correct |
2 |
Correct |
19 ms |
1340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
1408 KB |
Output is correct |
2 |
Correct |
11 ms |
1408 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
33 ms |
2672 KB |
Output is correct |
2 |
Correct |
66 ms |
4976 KB |
Output is correct |
3 |
Correct |
54 ms |
3952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
2412 KB |
Output is correct |
2 |
Correct |
76 ms |
5864 KB |
Output is correct |
3 |
Correct |
44 ms |
4332 KB |
Output is correct |
4 |
Correct |
67 ms |
5608 KB |
Output is correct |