Submission #880506

#TimeUsernameProblemLanguageResultExecution timeMemory
880506StefanL2005Type Printer (IOI08_printer)C++14
100 / 100
88 ms35920 KiB
#include <bits/stdc++.h> using namespace std; #define last Nod->fii.size() - 1 int nr = 0; struct Trie { int down, word; Trie *path; vector<pair<Trie*, char>> fii; Trie() { down = word = 0; path = 0; } }; Trie *Root = new Trie; void insert(Trie *Nod, char *p) { if (*p == '\0') { Nod->word++; return; } for (int i = 0; i < Nod->fii.size(); i++) if (*p == Nod->fii[i].second) { insert(Nod->fii[i].first, p + 1); if (Nod->fii[i].first->down + 1 > Nod->down) { Nod->path = Nod->fii[i].first; Nod->down = Nod->path->down + 1; } return; } nr++; Nod->fii.push_back(make_pair(new Trie, *p)); insert(Nod->fii[last].first, p + 1); if (Nod->fii[last].first->down + 1 > Nod->down) { Nod->down = Nod->fii[last].first-> down + 1; Nod->path = Nod->fii[last].first; } } void easy_search(Trie *Nod) { while (Nod->word > 0) { cout<< "P\n"; Nod->word--; } for (int i = 0; i < Nod->fii.size(); i++) { cout<< Nod->fii[i].second << "\n"; easy_search(Nod->fii[i].first); cout<< "-\n"; } } int show_longest(Trie *Nod, int k) { if (Nod->path == NULL) return k; return show_longest(Nod->path, k + 1); } void complex_search(Trie *Nod) { while (Nod->word > 0) { cout<< "P\n"; Nod->word--; } if (Nod->path == NULL) return; char let; for (int i = 0; i < Nod->fii.size(); i++) { if (Nod->fii[i].first == Nod->path) { let = Nod->fii[i].second; continue; } cout<< Nod->fii[i].second << "\n"; easy_search(Nod->fii[i].first); cout<< "-\n"; } cout<< let << "\n"; complex_search(Nod->path); } int main() { int N; cin>> N; for (int i = 0; i < N; i++) { string w; cin>> w; insert(Root, &w[0]); } cout<< (nr - Root->down) * 2 + Root->down + N << "\n"; complex_search(Root); return 0; }

Compilation message (stderr)

printer.cpp: In function 'void insert(Trie*, char*)':
printer.cpp:26:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<Trie*, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i = 0; i < Nod->fii.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~
printer.cpp: In function 'void easy_search(Trie*)':
printer.cpp:58:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<Trie*, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |     for (int i = 0; i < Nod->fii.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~
printer.cpp: In function 'void complex_search(Trie*)':
printer.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<Trie*, char> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   85 |     for (int i = 0; i < Nod->fii.size(); i++)
      |                     ~~^~~~~~~~~~~~~~~~~
printer.cpp:84:10: warning: 'let' may be used uninitialized in this function [-Wmaybe-uninitialized]
   84 |     char let;
      |          ^~~
#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...