Submission #802987

#TimeUsernameProblemLanguageResultExecution timeMemory
802987huantranType Printer (IOI08_printer)C++17
100 / 100
170 ms230596 KiB
#include <iostream> #include <algorithm> #include <cstring> #include <string.h> #include <vector> #include <map> #define bit(x, i) ((x >> i) & 1LL) using namespace std; typedef long long int ll; const int maxn = 1e6 + 5; int n, num = 0; vector<char> ans; struct Vertex{ ll next[27]; ll output = 0; ll sz; }; Vertex trie[maxn]; ll cnt = 1; void add_edge(string s) { ll u = 0; for(auto c : s) { if(!trie[u].next[c - 'a']) { trie[u].next[c - 'a'] = cnt++; } u = trie[u].next[c - 'a']; } trie[u].output++; } void trie_size(int u) { trie[u].sz = 1; for(int i = 0; i <= 25; i++) { if(trie[u].next[i] != 0) { trie_size(trie[u].next[i]); trie[u].sz = max(trie[u].sz, trie[trie[u].next[i]].sz + 1); } } } void get_ans(int u) { if(trie[u].output) { for(int i = 1; i <= trie[u].output && num < n; i++) { ans.push_back('P'); num++; } } vector<pair<ll, pair<ll, ll>>> e; for(int i = 0; i <= 25; i++) { if(trie[u].next[i] != 0) e.push_back({trie[trie[u].next[i]].sz, {trie[u].next[i], i}}); } sort(e.begin(), e.end()); for(int i = 0; i < e.size(); i++) { ans.push_back((char)('a' + e[i].second.second)); get_ans(e[i].second.first); if(num < n) ans.push_back('-'); } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; ll leng = 0; string t; for(int i = 1; i <= n; i++) { string s; cin >> s; add_edge(s); } trie_size(0); get_ans(0); cout << ans.size() << '\n'; for(auto j : ans) cout << j << '\n'; }

Compilation message (stderr)

printer.cpp: In function 'void get_ans(int)':
printer.cpp:70:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(int i = 0; i < e.size(); i++)
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:85:8: warning: unused variable 'leng' [-Wunused-variable]
   85 |     ll leng = 0;
      |        ^~~~
#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...