Submission #1010644

#TimeUsernameProblemLanguageResultExecution timeMemory
1010644Muaath_5Type Printer (IOI08_printer)C++17
0 / 100
64 ms38740 KiB
#include <bits/stdc++.h> #define ll long long const int N = 5001, MOD = 1e9+7; using namespace std; struct trie { char ch = 0; bool end = false; trie* chrs[26]; int mxdep = 0; }; int n; trie* root = new trie(); void add(string& x) { trie* cur = root; for (int i = 0; i < x.size(); i++) { if (!cur->chrs[x[i] - 'a']) cur->chrs[x[i] - 'a'] = new trie(); cur = cur->chrs[x[i] - 'a']; cur->ch = x[i]; } cur->end = true; } void dfs(trie* cur) { cur->mxdep = 1; for (trie* c : cur->chrs) { if (c) { dfs(c); cur->mxdep = max(cur->mxdep, c->mxdep+1); } } } int cnt = 0; void dfs2(trie* cur) { if (cur == nullptr) return; sort(cur->chrs, cur->chrs+26, [](trie* x, trie* y){ return (x ? x->mxdep : 0) < (y ? y->mxdep : 0); }); if (cur->ch != 0) cout << cur->ch << '\n'; if (cur->end) { cout << "P\n"; cnt++; if (cnt == n) exit(0); } for (int i = 0; i < 26; i++) { if (cur->chrs[i]) { dfs2(cur->chrs[i]); } } cout << "-\n"; } int main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n; for (int i = 0; i < n; i++) { string w; cin >> w; add(w); } dfs(root); dfs2(root); }

Compilation message (stderr)

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