Submission #659636

#TimeUsernameProblemLanguageResultExecution timeMemory
659636pakapuType Printer (IOI08_printer)C++17
100 / 100
120 ms101568 KiB
#include <bits/stdc++.h> using namespace std; struct node { node* c[26]; bool end = false; bool marked = false; node() { for(int i = 0; i < 26; i++) { c[i] = nullptr; } } }; vector<char> result; struct trie { node* head; trie() { head = new node; head -> marked = true; } void add(string s, bool m) { node* curr = head; for(int i = 0; i < s.size(); i++) { if(curr -> c[s[i] - 'a'] == nullptr) { curr -> c[s[i] - 'a'] = new node; } curr = curr -> c[s[i] - 'a']; curr -> marked = m; } curr -> end = true; } void out() { out(head, nullptr); } void out(node* v, node* prev) { if(v -> end) { result.push_back('P'); } int mi = -1; for(int i = 0; i < 26; i++) { if(v -> c[i] != nullptr) { if(v -> c[i] -> marked) { mi = i; continue; } result.push_back((char)(i + 'a')); out(v -> c[i], v); } } if(mi != -1) { result.push_back((char)(mi + 'a')); out(v -> c[mi], v); } if(!v -> marked) { result.push_back('-'); } } }; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; vector<string> a(n); string mx = ""; for(int i = 0; i < n; i++) { cin >> a[i]; if(a[i].size() > mx.size()) { mx = a[i]; } } trie t; for(auto c : a) { t.add(c, false); } t.add(mx, true); t.out(); assert(result.back() == 'P'); cout << result.size() << '\n'; for(auto c : result) { cout << c << '\n'; } return 0; }

Compilation message (stderr)

printer.cpp: In member function 'void trie::add(std::string, bool)':
printer.cpp:31:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |   for(int i = 0; i < s.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...