Submission #688607

#TimeUsernameProblemLanguageResultExecution timeMemory
688607danikoynovType Printer (IOI08_printer)C++14
100 / 100
153 ms106376 KiB
/** ____ ____ ____ ____ ____ ____ ||l |||e |||i |||n |||a |||d || ||__|||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\|/__\| **/ #include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } const int alphabet = 26; struct trie { trie *nxt[alphabet]; int max_depth, depth, word_cnt, front_move; trie(int _depth = 0) { for (int i = 0; i < alphabet; i ++) nxt[i] = NULL; word_cnt = 0, depth = _depth; max_depth = depth; front_move = -1; } }; void add(trie *root, string &word, int pos) { if (pos == word.size()) { root -> word_cnt ++; return; } int ch = word[pos] - 'a'; if (root -> nxt[ch] == NULL) root -> nxt[ch] = new trie(root -> depth + 1); add(root -> nxt[ch], word, pos + 1); if (root -> nxt[ch] -> max_depth > root -> max_depth) { root -> front_move = ch; root -> max_depth = root -> nxt[ch] -> max_depth; } } vector < char > path; void print(trie *root, bool save) { ///cout << root -> depth while(root -> word_cnt > 0) { path.push_back('P'); root -> word_cnt --; } for (int i = 0; i < alphabet; i ++) { if (root -> nxt[i] == NULL) continue; if (i != root -> front_move) { path.push_back((char)(i + 'a')); print(root -> nxt[i], false); path.push_back('-'); } } if (root -> front_move != -1) { path.push_back((char)(root -> front_move + 'a')); print(root -> nxt[root -> front_move], save); if (!save) path.push_back('-'); } } int n; trie *tree = new trie(0); void solve() { string word; cin >> n; for (int i = 1; i <= n; i ++) { cin >> word; add(tree, word, 0); } print(tree, true); cout << path.size() << endl; for (char c : path) cout << c << endl; } int main() { solve(); return 0; }

Compilation message (stderr)

printer.cpp: In function 'void add(trie*, std::string&, int)':
printer.cpp:42:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     if (pos == word.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...