Submission #900654

#TimeUsernameProblemLanguageResultExecution timeMemory
900654vaneaType Printer (IOI08_printer)C++17
10 / 100
67 ms40960 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mxN = 5e5+10; int trie[mxN][26]; int cnt = 0; bool stop[mxN]; string alpha = "abcdefghijklmnopqrstuvwxyz"; void insert(string s) { int node = 0; for(auto c : s) { if(trie[node][c-'a'] == 0) trie[node][c-'a'] = ++cnt; node = trie[node][c-'a']; } stop[node] = true; } vector<char> ans; void dfs(int node) { if(stop[node]) ans.push_back('P'); for(auto c : alpha) { int k = trie[node][c-'a']; if(k) { ans.push_back(c); dfs(k); ans.push_back('-'); } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n; cin >> n; for(int i = 0; i < n; i++) { string s; cin >> s; insert(s); } dfs(0); int curr = 0, mx = 0, idx; for(int i = 0; i < ans.size(); i++) { if(ans[i] == '-') curr++; else { if(curr > mx) { mx = curr; idx = i; } curr = 0; } } cout << ans.size() - mx << '\n'; for(int i = idx; i < ans.size(); i++) { cout << ans[i] << '\n'; } for(int i = 0; i < idx-mx; i++) { cout << ans[i] << '\n'; } return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:48:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   48 |     for(int i = 0; i < ans.size(); i++) {
      |                    ~~^~~~~~~~~~~~
printer.cpp:59:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for(int i = idx; i < ans.size(); i++) {
      |                      ~~^~~~~~~~~~~~
printer.cpp:62:27: warning: 'idx' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |     for(int i = 0; i < idx-mx; 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...