#include <bits/stdc++.h>
#include <fstream>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define INF 1000000000
#define INF2 2000000000
#define fi first
#define se second
using namespace std;
double const EPS = 1e-14;
const int P = 1007;
typedef long long ll;
using namespace __gnu_pbds;
typedef long long ll;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; // find_by_order, order_of_key
const int N = 100000;
pair<int,int> tr[N][26];
int cnt = 1, sum = 0, indx = 0;
string ss, ans;
void sol(string s) {
int now = 0;
for(int i = 0; i < s.size(); i++) {
if(tr[now][s[i]-'a'].fi == 0) {
tr[now][s[i]-'a'].fi = cnt;
cnt++;
if(i+1 == s.size()) tr[now][s[i]-'a'].se = 1;
}
now = tr[now][s[i]-'a'].fi;
}
}
void dfs(int cur, int len) {
for(int i = 0; i < 26; i++) {
if(indx == len && i == ss[len]-'a') continue;
if(tr[cur][i].fi != 0) {
char c = 'a'; c += i;
ans.push_back(c);
if(tr[cur][i].se == 1) ans.push_back('P');
dfs(tr[cur][i].fi,len+1);
ans.push_back('-');
}
}
if(len != indx) return;
// cout << len << ' ' << ss[len] << endl;
ans.push_back(ss[len]);
if(tr[cur][ss[len]-'a'].se == 1) {
ans.push_back('P'); return;
}
indx++; dfs(tr[cur][ss[len]-'a'].fi,len+1);
}
int main()
{
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
int n; cin >> n;
for(int i = 0; i < n; i++) {
string s; cin >> s;
sol(s);
if(s.size() > ss.size()) ss = s;
}
dfs(0,0);
cout << ans.size() << endl;
for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
return 0;
}
Compilation message
printer.cpp: In function 'void sol(std::string)':
printer.cpp:25:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
printer.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | if(i+1 == s.size()) tr[now][s[i]-'a'].se = 1;
| ~~~~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:64:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
| ~~^~~~~~~~~~~~
# |
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 |
1 ms |
464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
1880 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
5720 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
14 ms |
13804 KB |
didn't print every word |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
26 ms |
41808 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
26 ms |
41820 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |