Submission #310649

#TimeUsernameProblemLanguageResultExecution timeMemory
310649AkashiType Printer (IOI08_printer)C++14
100 / 100
367 ms99888 KiB
#include <bits/stdc++.h> using namespace std; struct Trie { Trie *fii[26]; int cnt, mx; Trie(){memset(fii, NULL, sizeof(fii)); cnt = mx = 0;} }; Trie *T = new Trie; int t; char s[25]; void add(Trie *nod, char *p){ if (*p == NULL) { nod->cnt++; return ; } if (nod->fii[*p - 'a'] == NULL) nod->fii[*p - 'a'] = new Trie; add(nod->fii[*p - 'a'], p + 1); nod->mx = max(nod->mx, nod->fii[*p - 'a']->mx + 1); } string sol; void parc(Trie *nod = T) { if (nod->cnt) sol.push_back('P'); int wh = -1, mx = -1; int cnt = 0; for (int i = 0; i < 26 ; ++i) { if (nod->fii[i] == NULL) continue ; if (nod->fii[i]->mx > mx) mx = nod->fii[i]->mx, wh = i; ++cnt; } if (cnt > 1) cerr << cnt << " " << mx << " " << (char)(wh + 'a') << endl; if (wh == -1) return ; for (int i = 0; i < 26 ; ++i) { if (nod->fii[i] == NULL || i == wh) continue ; sol.push_back(i + 'a'); parc(nod->fii[i]); sol.push_back('-'); } sol.push_back(wh + 'a'); parc(nod->fii[wh]); sol.push_back('-'); } int main() { scanf("%d", &t); for (int i = 1; i <= t ; ++i) { scanf("%s", s); add(T, s); } parc(); while (sol.back() == '-') sol.pop_back(); printf("%d\n", sol.size()); for (auto it : sol) printf("%c\n", it); return 0; }

Compilation message (stderr)

printer.cpp: In constructor 'Trie::Trie()':
printer.cpp:8:21: warning: passing NULL to non-pointer argument 2 of 'void* memset(void*, int, size_t)' [-Wconversion-null]
    8 |  Trie(){memset(fii, NULL, sizeof(fii)); cnt = mx = 0;}
      |                     ^~~~
In file included from /usr/include/features.h:367,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/c++config.h:524,
                 from /usr/include/c++/9/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:33,
                 from printer.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string3.h:78:1: note:   declared here
   78 | __NTH (memset (void *__dest, int __ch, size_t __len))
      | ^~~~~
printer.cpp: In function 'void add(Trie*, char*)':
printer.cpp:17:12: warning: NULL used in arithmetic [-Wpointer-arith]
   17 |  if (*p == NULL) {
      |            ^~~~
printer.cpp: In function 'int main()':
printer.cpp:66:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wformat=]
   66 |  printf("%d\n", sol.size());
      |          ~^     ~~~~~~~~~~
      |           |             |
      |           int           std::__cxx11::basic_string<char>::size_type {aka long unsigned int}
      |          %ld
printer.cpp:56:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   56 |  scanf("%d", &t);
      |  ~~~~~^~~~~~~~~~
printer.cpp:58:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   58 |   scanf("%s", s);
      |   ~~~~~^~~~~~~~~
#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...