Submission #716345

#TimeUsernameProblemLanguageResultExecution timeMemory
716345kartapolovType Printer (IOI08_printer)C++14
90 / 100
1078 ms119988 KiB
#include<bits/stdc++.h> using namespace std; struct vertex { bool term = 0; vector<vertex*> children = vector<vertex*>(26, nullptr); vertex() = default; void add(const string& s, int i = 0) { if (this->children[s[i] - 'a'] == nullptr) { this->children[s[i] - 'a'] = new vertex(); } if (i + 1 == s.size()) { (this->children[s[i] - 'a']->term) = true; } else { this->children[s[i] - 'a']->add(s, i + 1); } } }; vector<char> ans; string maxw = ""; int n, k; void dfs(vertex* v, int h = 0) { if (v->term) { ans.push_back('P'); ++k; } for (int i = 0; i < 26; ++i) { if (!(h < maxw.size() and i == maxw[h] - 'a') and (v->children[i] != nullptr)) { ans.push_back(i + 'a'); dfs(v->children[i], h + 1); if (k != n) ans.push_back('-'); } } if (h < maxw.size() and v->children[maxw[h] - 'a'] != nullptr) { ans.push_back(maxw[h]); dfs(v->children[maxw[h] - 'a'], h + 1); if (k != n) ans.push_back('-'); } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); cin >> n; vertex root; for (int i = 0; i < n; ++i) { string word; cin >> word; if (word.size() > maxw.size()) maxw = word; root.add(word); } k = 0; dfs(&root); cout << ans.size() << endl; for (char c : ans) cout << c << endl; }

Compilation message (stderr)

printer.cpp: In member function 'void vertex::add(const string&, int)':
printer.cpp:12:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |         if (i + 1 == s.size()) {
      |             ~~~~~~^~~~~~~~~~~
printer.cpp: In function 'void dfs(vertex*, int)':
printer.cpp:29:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         if (!(h < maxw.size() and i == maxw[h] - 'a') and (v->children[i] != nullptr)) {
      |               ~~^~~~~~~~~~~~~
printer.cpp:36:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   36 |     if (h < maxw.size() and v->children[maxw[h] - 'a'] != nullptr) {
      |         ~~^~~~~~~~~~~~~
#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...