# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
982721 | vjudge1 | Type Printer (IOI08_printer) | C++17 | 73 ms | 49924 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<iostream>
#include<string>
#include<algorithm>
#define optimizar_io ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
int n;
struct node{
bool w, l;
int hijos[26];
};
node trie[500002];
int t;
int maxi;
string word, larger;
void mete( string word, bool p ){
int pos = 0;
for( int i = 0; i < word.size(); i++ ){
int letra = ( word[i] - 'a' );
trie[pos].hijos[letra] = trie[pos].hijos[letra] ? trie[pos].hijos[letra] : ++t;
pos = trie[pos].hijos[letra];
trie[pos].l = p;
}
trie[pos].w = true;
trie[pos].l = p;
}
string ans;
void recorre( int nodo ){
if( trie[nodo].w )
ans+= "P";
int pending = -1, hijo;
for( int i = 0; i < 26; i++ ){
if( trie[nodo].hijos[i] ){
hijo = trie[nodo].hijos[i];
if( trie[hijo].l ){
pending = i;
continue;
}
ans.push_back( (char)(i) + 'a' );
recorre( hijo );
ans += "-";
}
}
if( pending != -1 ){
ans.push_back( (char)(pending) + 'a' );
recorre( trie[nodo].hijos[pending] );
}
}
int main(){
optimizar_io
cin >> n;
for( int i = 1; i <= n; i++ ){
cin >> word;
mete( word, 0 );
if( word.size() > maxi ){
maxi = word.size();
larger = word;
}
}
mete( larger, 1 );
recorre( 0 );
cout << ans.size() << "\n";
for( int i = 0; i < ans.size(); i++ )
cout << ans[i] << "\n";
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... |