Submission #746977

#TimeUsernameProblemLanguageResultExecution timeMemory
746977khulegubType Printer (IOI08_printer)C++14
20 / 100
75 ms53188 KiB
#include <bits/stdc++.h> using namespace std; const int N = 500005; /** Node count*/ int k = 1; int to[N][26]; char a[N]; int h[N]; bool last[N]; vector<char> ans; void calc_height(int u) { int height = 0; for (int i = 0; i < 26; i++) { if (to[u][i] != -1) { int v = to[u][i]; calc_height(v); height = max(height, 1 + h[v]); } } h[u] = height; } void dfs(int u) { if (u > 0) ans.push_back(a[u]); vector<pair<int, int> > children; for (int i = 0; i < 26; i++) { if (to[u][i] != -1) { int v = to[u][i]; children.push_back({h[v], v}); } } sort(children.begin(), children.end()); for (int i = 0; i < children.size(); i++) { int v = children[i].second; dfs(v); } if (last[u]) { ans.push_back('P'); } if (u > 0) ans.push_back('-'); } int main() { int n; cin >> n; memset(to, -1, sizeof to); for (int i = 0; i < n; i++) { string s; cin >> s; int curr = 0; for (int j = 0; j < s.length(); j++) { int c = s[j] - 'a'; if (to[curr][c] == -1) { // Create a new node. to[curr][c] = k; k++; } a[to[curr][c]] = s[j]; curr = to[curr][c]; } // Mark the end of the word. last[curr] = true; } calc_height(0); dfs(0); while (ans.size() > 0 && ans.back() == '-') ans.pop_back(); cout << ans.size() << '\n'; for (char c : ans) cout << c << '\n'; }

Compilation message (stderr)

printer.cpp: In function 'void dfs(int)':
printer.cpp:42:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for (int i = 0; i < children.size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:66:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   66 |     for (int j = 0; j < s.length(); j++) {
      |                     ~~^~~~~~~~~~~~
#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...