Submission #982721

#TimeUsernameProblemLanguageResultExecution timeMemory
982721vjudge1Type Printer (IOI08_printer)C++17
100 / 100
73 ms49924 KiB
#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)

printer.cpp: In function 'void mete(std::string, bool)':
printer.cpp:21:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |  for( int i = 0; i < word.size(); i++ ){
      |                  ~~^~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:70:19: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |   if( word.size() > maxi ){
      |       ~~~~~~~~~~~~^~~~~~
printer.cpp:79:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |  for( int i = 0; i < ans.size(); i++ )
      |                  ~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...