# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1093979 | clementine | Type Printer (IOI08_printer) | C++17 | 68 ms | 37612 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 k = 26;
struct Node
{
bool isend = false;
int next[k];
bool big[k];
Node(){
fill(begin(next), end(next), -1);
}
};
vector<Node> trie;
void addstring(string s)
{
int v = 0;
for(auto ch : s)
{
int c = ch - 'a';
if(trie[v].next[c] == -1)
{
trie[v].next[c] = trie.size();
trie.emplace_back();
}
v = trie[v].next[c];
cout << v << '\n';
}
trie[v].isend = true;
}
void addbig(string s)
{
int v = 0;
for(auto ch : s)
{
int c = ch - 'a';
if(trie[v].next[c] == -1)
{
trie[v].next[c] = trie.size();
trie.emplace_back();
}
trie[v].big[c] = true;
v = trie[v].next[c];
cout << v << '\n';
}
trie[v].isend = true;
}
vector<char> ans;
void dfs(int u)
{
//cout << "this is u : " << u << "\n";
if(trie[u].isend)
{
ans.push_back('P');
//cout << " one \n";
}
for(int i = 0; i < k; i ++)
{
if(trie[u].next[i] != -1 && !trie[u].big[i])
{
ans.push_back('a' + i);
//cout << "two \n";
dfs(trie[u].next[i]);
ans.push_back('-');
}
}
for(int i = 0; i < k; i ++)
{
if(trie[u].next[i] != -1 && trie[u].big[i])
{
ans.push_back('a' + i);
//cout << "foutr \n";
dfs(trie[u].next[i]);
ans.push_back('-');
}
}
}
int main()
{
int n;
cin >> n;
vector<string> s;
trie.emplace_back();
for(int i = 0; i < n; i ++)
{
string a;
cin >> a;
s.push_back(a);
}
sort(s.begin(), s.end(), [](string a, string b){return a.length() < b.length();});
//cout << s[n-1] << "!!!!! \n";
for(int i = 0; i < n-1; i ++)
{
addstring(s[i]);
}
addbig(s[n-1]);
dfs(0);
for(int i = ans.size() - 1; ans[i] != 'P'; i --)
{
ans.pop_back();
}
cout << ans.size() << '\n';
for(int i = 0; i < ans.size() ; i ++)
{
cout << ans[i] << '\n';
}
}
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... |