# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
880506 | StefanL2005 | Type Printer (IOI08_printer) | C++14 | 88 ms | 35920 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 last Nod->fii.size() - 1
int nr = 0;
struct Trie {
int down, word;
Trie *path;
vector<pair<Trie*, char>> fii;
Trie() {
down = word = 0; path = 0;
}
};
Trie *Root = new Trie;
void insert(Trie *Nod, char *p)
{
if (*p == '\0')
{
Nod->word++;
return;
}
for (int i = 0; i < Nod->fii.size(); i++)
if (*p == Nod->fii[i].second)
{
insert(Nod->fii[i].first, p + 1);
if (Nod->fii[i].first->down + 1 > Nod->down)
{
Nod->path = Nod->fii[i].first;
Nod->down = Nod->path->down + 1;
}
return;
}
nr++;
Nod->fii.push_back(make_pair(new Trie, *p));
insert(Nod->fii[last].first, p + 1);
if (Nod->fii[last].first->down + 1 > Nod->down)
{
Nod->down = Nod->fii[last].first-> down + 1;
Nod->path = Nod->fii[last].first;
}
}
void easy_search(Trie *Nod)
{
while (Nod->word > 0)
{
cout<< "P\n";
Nod->word--;
}
for (int i = 0; i < Nod->fii.size(); i++)
{
cout<< Nod->fii[i].second << "\n";
easy_search(Nod->fii[i].first);
cout<< "-\n";
}
}
int show_longest(Trie *Nod, int k)
{
if (Nod->path == NULL)
return k;
return show_longest(Nod->path, k + 1);
}
void complex_search(Trie *Nod)
{
while (Nod->word > 0)
{
cout<< "P\n";
Nod->word--;
}
if (Nod->path == NULL)
return;
char let;
for (int i = 0; i < Nod->fii.size(); i++)
{
if (Nod->fii[i].first == Nod->path)
{
let = Nod->fii[i].second;
continue;
}
cout<< Nod->fii[i].second << "\n";
easy_search(Nod->fii[i].first);
cout<< "-\n";
}
cout<< let << "\n";
complex_search(Nod->path);
}
int main()
{
int N;
cin>> N;
for (int i = 0; i < N; i++)
{
string w; cin>> w;
insert(Root, &w[0]);
}
cout<< (nr - Root->down) * 2 + Root->down + N << "\n";
complex_search(Root);
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... |