Submission #922062

#TimeUsernameProblemLanguageResultExecution timeMemory
922062SyriusType Printer (IOI08_printer)C++14
100 / 100
124 ms99536 KiB
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define ff first #define ss second #define pint pair < int , int > #define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL) const int inf = 1e9 + 9; const int mxn = 1e6 + 2; const int mod = 1e9 + 7; struct node { bool ends , path; node *branch[26]; node () { ends = path = 0; for (int i = 0; i < 26; i++) branch[i] = NULL; } }; void insert(node *root , string s) { for (int i = 0; i < s.size(); i++) { int id = s[i] - 'a'; if (root -> branch[id] == NULL) root -> branch[id] = new node(); root = root -> branch[id]; } root -> ends = 1; } void createpath(node *root , string s) { for (int i = 0; i < s.size(); i++) { int id = s[i] - 'a'; root -> branch[id] -> path = 1; root = root -> branch[id]; } } vector < char > ans; void print(node *root) { node *go = NULL; char add; if (root -> ends) ans.push_back('P'); for (int i = 0; i < 26; i++) { if (root -> branch[i] == NULL) continue; if (root -> branch[i] -> path) { go = root -> branch[i]; add = i + 'a'; continue; } ans.push_back(i + 'a'); print(root -> branch[i]); ans.push_back('-'); } if (go != NULL) { ans.push_back(add); print(go); } } int main() { int n; cin >> n; node *root = new node(); string mx; int sz = 0; for (int i = 0; i < n; i++) { string s; cin >> s; insert(root , s); if (s.size() > sz) { mx = s; sz = s.size(); } } createpath(root , mx); print(root); cout << ans.size() << '\n'; for (int i = 0; i < ans.size(); i++) cout << ans[i] << '\n'; return 0; }

Compilation message (stderr)

printer.cpp: In function 'void insert(node*, std::string)':
printer.cpp:25:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
printer.cpp: In function 'void createpath(node*, std::string)':
printer.cpp:34:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |  for (int i = 0; i < s.size(); i++) {
      |                  ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:78:16: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |   if (s.size() > sz) {
      |       ~~~~~~~~~^~~~
printer.cpp:88:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |  for (int i = 0; i < ans.size(); i++) cout << ans[i] << '\n';
      |                  ~~^~~~~~~~~~~~
#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...