# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
857804 | vjudge1 | Type Printer (IOI08_printer) | C++17 | 92 ms | 37196 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 <cstdio>
#include <cstring>
#include <cassert>
#include <string>
#include <deque>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <iostream>
#include <utility>
using namespace std;
using ll=long long;
#define N 200005
#define ALL(x) x.begin(), x.end()
vector<char> ans;
int cend2;
int n;
char s[21];
struct Trie
{
int start = 0, end = 0, sz = 1;
vector<tuple<int, char,Trie*>> sortbysz;
Trie() {}
void insert(char *s, int p = 0)
{
if (!*s) { ++end; return; }
if (p == 1) ++start;
char c = *s++;
for (auto [sz, ch, n] : sortbysz)
if (ch == c)
{ n->insert(s); return; }
Trie *n = new Trie();
sortbysz.emplace_back(1, c, n);
n->insert(s);
}
void preprocess()
{
for (auto &[csz, c, n] : sortbysz)
{
n->preprocess();
sz = max(sz, csz = n->sz+1);
}
sort(ALL(sortbysz));
}
void print()
{
while (end--)
{
ans.push_back('P');
if (++cend2 == n)
{
printf("%d\n", (int)ans.size());
for (char c : ans) printf("%c\n", c);
exit(0);
}
}
for (auto [sz, c, n] : sortbysz)
{
ans.push_back(c);
n->print();
}
ans.push_back('-');
}
};
int main()
{
scanf("%d", &n);
Trie *t = new Trie();
for (int i = 0; i < n; ++i)
{
scanf("%s", s);
t->insert(s);
}
t->preprocess();
t->print();
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... |