Submission #746178

#TimeUsernameProblemLanguageResultExecution timeMemory
746178khulegubType Printer (IOI08_printer)C++17
0 / 100
22 ms21460 KiB
#include <bits/stdc++.h> using namespace std; const int N = 100000; /** Node count*/ int k = 1; int to[N][26]; char a[N]; vector<char> ans; void dfs(int u) { if (u > 0) ans.push_back(a[u]); bool is_leaf = true; for (int i = 0; i < 26; i++) { if (to[u][i] != -1) { is_leaf = false; dfs(to[u][i]); } } if (is_leaf) { ans.push_back('P'); } 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]; } } dfs(0); vector<pair<int, string> > v; string last = ""; int longest = -1; int p_count = 0; for (int i = 0; i < ans.size(); i++) { if (ans[i] == '-') { if (last != "") { v.push_back({1, last}); last = ""; } else { v.back().first++; longest = max(longest, v.back().first); } } else { if (ans[i] == 'P') { p_count++; } last += (ans[i]); } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); cout << ans.size() - longest - p_count << endl; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].second.length(); j++) { cout << v[i].second[j] << '\n'; } if (i < v.size() -1) { for (int j = 0; j < v[i].first - 1; j++) { cout << '-' << '\n'; } } } }

Compilation message (stderr)

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