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>
using namespace std;
int t,trie[500005][27],n,node,cnt=0,hsh[500005],mx=-1,print=0;
char s[25],phero[25];
vector<char> krit;
void dfs(int u,int lv)
{
//printf("%d %d\n",u,lv);
if(hsh[u]!=0)
{
krit.push_back('P');
++print;
}
for(int i=0;i<26;i++)
{
if('a'+i!=phero[lv])
if(trie[u][i]!=-1)
{
//printf("%d %d %d %c\n",u,lv,trie[u][i],'a'+i);
krit.push_back('a'+i);
dfs(trie[u][i],lv+1);
//printf("reyna\n");
if(print!=t)
krit.push_back('-');
}
}
if(trie[u][phero[lv]-'a']!=-1&&lv<=mx)
{
krit.push_back(phero[lv]);
dfs(trie[u][phero[lv]-'a'],lv+1);
if(print!=t)
krit.push_back('-');
}
}
int main()
{
memset(trie,-1,sizeof trie);
scanf("%d",&t);
for(int j=1;j<=t;j++)
{
scanf("%s",s+1);
n=0;
for(int i=1;s[i];i++)++n;
node=0;
for(int i=1;i<=n;i++)
{
if(trie[node][s[i]-'a']==-1)
{
++cnt;
trie[node][s[i]-'a']=cnt;
}
node=trie[node][s[i]-'a'];
}
hsh[node]=j;
if(n>mx)
{
mx=n;
for(int i=1;i<=n;i++)phero[i]=s[i];
}
}
dfs(0,1);
printf("%d\n",krit.size());
for(int i=0;i<krit.size();i++)
{
printf("%c\n",krit[i]);
}
}
/*
3
print
the
poem
*/
Compilation message (stderr)
printer.cpp: In function 'int main()':
printer.cpp:64:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
64 | printf("%d\n",krit.size());
| ~^ ~~~~~~~~~~~
| | |
| int std::vector<char>::size_type {aka long unsigned int}
| %ld
printer.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | for(int i=0;i<krit.size();i++)
| ~^~~~~~~~~~~~
printer.cpp:40:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
40 | scanf("%d",&t);
| ~~~~~^~~~~~~~~
printer.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%s",s+1);
| ~~~~~^~~~~~~~~~
# | 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... |