Submission #1083546

#TimeUsernameProblemLanguageResultExecution timeMemory
1083546SulAType Printer (IOI08_printer)C++17
0 / 100
40 ms36128 KiB
#include <bits/stdc++.h> using namespace std; struct trie { trie* child[26] = {}; bool end = false; void insert(const string& s, int ind = 0) { if (ind == s.size()) { end = true; } else { if (child[ s[ind] - 'a' ] == nullptr) child[ s[ind] - 'a' ] = new trie(); child[ s[ind] - 'a' ]->insert(s, ind + 1); } } void dfs(const string& longest, int ind = 0, bool branch = true) { if (end) { cout << "P\n"; } if (branch) { for (int i = 0; i < 26; i++) if (i + 'a' != longest[ind] && child[i] != nullptr) { cout << char(i + 'a') << "\n"; child[i]->dfs(longest, ind + 1, false); cout << "-\n"; } if (ind < longest.size()) { cout << longest[ind] << '\n'; child[ longest[ind] - 'a' ]->dfs(longest, ind + 1, true); } } else { for (int i = 0; i < 26; i++) if (child[i] != nullptr) { cout << char(i + 'a') << "\n"; child[i]->dfs(longest, ind + 1, false); cout << "-\n"; } } } }; trie* root = new trie(); int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; string longest; while (n--) { string s; cin >> s; root->insert(s); if (s.size() > longest.size()) { swap(s, longest); } } root->dfs(longest); }

Compilation message (stderr)

printer.cpp: In member function 'void trie::insert(const string&, int)':
printer.cpp:9:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    9 |         if (ind == s.size()) {
      |             ~~~~^~~~~~~~~~~
printer.cpp: In member function 'void trie::dfs(const string&, int, bool)':
printer.cpp:27:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |             if (ind < longest.size()) {
      |                 ~~~~^~~~~~~~~~~~~~~~
#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...