#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return 63 - __builtin_clzll(mask);}
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
// mt19937_64 rng(69);
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
template <class T1, class T2>
bool maximize(T1 &a, T2 b){
if (a < b) {a = b; return true;}
return false;
}
template <class T1, class T2>
bool minimize(T1 &a, T2 b){
if (a > b) {a = b; return true;}
return false;
}
template <class T>
void printArr(T& container, string separator = " ", string finish = "\n", ostream &out = cout){
for(auto item: container) out << item << separator;
out << finish;
}
template <class T>
void remove_dup(vector<T> &a){
sort(ALL(a));
a.resize(unique(ALL(a)) - a.begin());
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n; cin >> n;
vector<string> a(n);
for(int i = 0; i<n; ++i) cin >> a[i];
string ma = "";
for(string i: a){
if (ma.size() < i.size()) ma = i;
}
vector<int> debuff(ma.size());
for(int i = 0; i<ma.size(); ++i) debuff[i] = ma[i] - 'a' + 1;
for(string &i: a){
for(int j = 0; j < i.size(); ++j){
int digit = i[j] - 'a';
digit = (digit - debuff[j] + 26) % 26;
i[j] = digit + 'a';
}
}
sort(ALL(a));
for(string &i: a){
for(int j = 0; j < i.size(); ++j){
int digit = i[j] - 'a';
digit = (digit + debuff[j]) % 26;
i[j] = digit + 'a';
}
}
vector<string> ans;
for(char c: a[0]) ans.push_back(string(1, c));
ans.push_back("P");
for(int i = 1; i<n; ++i){
int lcp = 0;
for(int j = 0; j < min(a[i-1].size(), a[i].size()); ++j){
if (a[i-1][j] != a[i][j]) break;
lcp++;
}
for(int j = a[i-1].size() - 1; j>=lcp; --j){
ans.push_back("-");
}
for(int j = lcp; j<a[i].size(); ++j)
ans.push_back(string(1, a[i][j]));
ans.push_back("P");
}
cout << ans.size() << "\n";
for(string i: ans) cout << i << "\n";
return 0;
}
Compilation message
printer.cpp: In function 'int main()':
printer.cpp:62:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i = 0; i<ma.size(); ++i) debuff[i] = ma[i] - 'a' + 1;
| ~^~~~~~~~~~
printer.cpp:65:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int j = 0; j < i.size(); ++j){
| ~~^~~~~~~~~~
printer.cpp:75:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for(int j = 0; j < i.size(); ++j){
| ~~^~~~~~~~~~
printer.cpp:87:26: warning: comparison of integer expressions of different signedness: 'int' and 'const long unsigned int' [-Wsign-compare]
87 | for(int j = 0; j < min(a[i-1].size(), a[i].size()); ++j){
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
printer.cpp:94:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int j = lcp; j<a[i].size(); ++j)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
984 KB |
Output is correct |
2 |
Correct |
2 ms |
1604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
2768 KB |
Output is correct |
2 |
Correct |
11 ms |
5964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9932 KB |
Output is correct |
2 |
Correct |
8 ms |
3288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
29 ms |
18392 KB |
Output is correct |
2 |
Correct |
61 ms |
36808 KB |
Output is correct |
3 |
Correct |
35 ms |
21192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
32 ms |
17864 KB |
Output is correct |
2 |
Correct |
67 ms |
37852 KB |
Output is correct |
3 |
Correct |
39 ms |
19912 KB |
Output is correct |
4 |
Correct |
60 ms |
37212 KB |
Output is correct |