# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1098152 | rayan_bd | Type Printer (IOI08_printer) | C++17 | 162 ms | 124100 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;
const int INF = (int)1e9;
vector<char> ans;
struct Node
{
Node *children[26];
bool end;
int mnLen;
set<pair<int, char>> st;
char mnC;
Node()
{
for (int i = 0; i < 26; ++i)
children[i] = NULL;
end = 0;
mnLen = INF;
mnC = '*';
};
};
Node *root = new Node();
struct Trie
{
void insert(string str)
{
Node *curr_node = root;
for (auto it : str)
{
if (curr_node->children[it - 'a'] == NULL)
{
curr_node->children[it - 'a'] = new Node();
}
vector<int> for_del;
for (auto itt : curr_node->st)
{
if (itt.second == it)
{
for_del.push_back(itt.first);
}
}
for (auto itt : for_del)
curr_node->st.erase({itt, it});
curr_node->st.insert({(int)str.size(), it});
curr_node = curr_node->children[it - 'a'];
}
curr_node->end = 1;
}
void qry(Node *curr)
{
bool flag = 1;
for (int i = 0; i < 26; ++i)
{
if (curr->children[i] != NULL)
{
flag = 0;
}
}
if (curr->end == 1)
{
ans.push_back('P');
}
if (flag)
{
ans.push_back('-');
return;
}
for (auto it : curr->st)
{
ans.push_back(it.second);
qry(curr->children[it.second - 'a']);
}
ans.push_back('-');
}
} t;
void solve()
{
int n;
cin >> n;
string str;
for (int i = 0; i < n; ++i)
{
cin >> str;
t.insert(str);
}
Node *curr_node = root;
t.qry(curr_node);
int deletee = 0;
for (int i = ans.size() - 1; i >= 0; --i)
{
if (ans[i] == '-')
{
++deletee;
}
else
{
break;
}
}
cout << ans.size() - deletee << '\n';
for (int i = 0; i < ans.size() - deletee; ++i)
{
cout << ans[i] << '\n';
}
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
solve();
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... |