# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
115189 | ly20 | Type Printer (IOI08_printer) | C++14 | 177 ms | 61540 KiB |
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;
#define debug(args...) //fprintf(stderr,args)
const int MAXN=25010,MAXL=30;
int trie[MAXN*MAXL][MAXL],vl[MAXN*MAXL],cont[MAXN*MAXL],pos[MAXN*MAXL],end1[MAXN*MAXL],pt[MAXN*MAXL];
int at;
vector<char> rs;
string s1;
string sr;
int tmn;
void tr(int v)
{
for(int i=0;i<MAXL;i++)
{
if(trie[v][i]!=0 && pt[trie[v][i]]!=1)
{
rs.push_back(vl[trie[v][i]]+'a');
if(end1[trie[v][i]])rs.push_back('P');
tr(trie[v][i]);
rs.push_back('-');
}
}
int id;
if(tmn>pos[v])
{
id=sr[pos[v]]-'a';
if(pt[trie[v][id]]==1)
{
rs.push_back(vl[trie[v][id]]+'a');
if(end1[trie[v][id]])rs.push_back('P');
tr(trie[v][id]);
}
}
}
void add(string s)
{
int cur=0;
int tm=s.size();
for(int i=0;i<tm;i++)
{
cont[cur]++;
int id=s[i]-'a';
if(trie[cur][id]==0)
{
trie[cur][id]=++at;
vl[at]=id;
pos[at]=i+1;
}
cur=trie[cur][id];
}
end1[cur]=1;
}
void pt1(string s)
{
int cur=0;
int tm=s.size();
for(int i=0;i<tm;i++)
{
int id=s[i]-'a';
cur=trie[cur][id];
pt[cur]=1;
}
}
int main()
{
int n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
cin>>s1;
if(s1.size()>sr.size())sr=s1;
add(s1);
}
pt1(sr);
tmn=sr.size();
tr(0);
printf("%d\n",rs.size());
for(int i=0;i<rs.size();i++)printf("%c\n",rs[i]);
return 0;
}
Compilation message (stderr)
# | 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... |