This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 1;
const int mod = 1e9 + 7;
int child[N][26], dp[N], depth[N], h[N], id[N], par[N];
map<int,int> pos[N];
set<int> chk[N];
int cnt = 0, n;
string s[N];
void insertword(string word,int num)
{
int node = 0, cur = 0;
chk[num].insert(0);
for(auto k : word)
{
if(child[node][k - 'a'] == 0)
{
child[node][k - 'a'] = ++cnt;
par[cnt] = node;
depth[cnt] = depth[node] + 1;
}
node = child[node][k - 'a'];
chk[num].insert(node);
pos[num][node] = cur + 1;
cur++;
}
h[num] = depth[node];
}
bool mmb(int a,int b)
{
return h[a] < h[b];
}
int32_t main()
{
// freopen("test.inp", "r" ,stdin);
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++)
{
cin >> s[i];
insertword(s[i], i);
id[i] = i;
}
vector<char> ans, curr;
sort(id + 1, id + n + 1, mmb);
int node = 0;
for(int i = 1; i <= n; i++)
{
while(chk[id[i]].find(node) == chk[id[i]].end()) node = par[node], ans.push_back('-');
for(int j = pos[id[i]][node]; j < s[id[i]].size(); j++)
{
node = child[node][s[id[i]][j] - 'a'];
ans.push_back(s[id[i]][j]);
}
ans.push_back('P');
}
cout << ans.size() <<'\n';
for(auto k : ans) cout << k<<'\n';
}
Compilation message (stderr)
printer.cpp: In function 'int32_t main()':
printer.cpp:61:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
61 | for(int j = pos[id[i]][node]; j < s[id[i]].size(); j++)
| ~~^~~~~~~~~~~~~~~~~
# | 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... |