Submission #857804

#TimeUsernameProblemLanguageResultExecution timeMemory
857804vjudge1Type Printer (IOI08_printer)C++17
100 / 100
92 ms37196 KiB
#include <cstdio> #include <cstring> #include <cassert> #include <string> #include <deque> #include <vector> #include <map> #include <queue> #include <algorithm> #include <iostream> #include <utility> using namespace std; using ll=long long; #define N 200005 #define ALL(x) x.begin(), x.end() vector<char> ans; int cend2; int n; char s[21]; struct Trie { int start = 0, end = 0, sz = 1; vector<tuple<int, char,Trie*>> sortbysz; Trie() {} void insert(char *s, int p = 0) { if (!*s) { ++end; return; } if (p == 1) ++start; char c = *s++; for (auto [sz, ch, n] : sortbysz) if (ch == c) { n->insert(s); return; } Trie *n = new Trie(); sortbysz.emplace_back(1, c, n); n->insert(s); } void preprocess() { for (auto &[csz, c, n] : sortbysz) { n->preprocess(); sz = max(sz, csz = n->sz+1); } sort(ALL(sortbysz)); } void print() { while (end--) { ans.push_back('P'); if (++cend2 == n) { printf("%d\n", (int)ans.size()); for (char c : ans) printf("%c\n", c); exit(0); } } for (auto [sz, c, n] : sortbysz) { ans.push_back(c); n->print(); } ans.push_back('-'); } }; int main() { scanf("%d", &n); Trie *t = new Trie(); for (int i = 0; i < n; ++i) { scanf("%s", s); t->insert(s); } t->preprocess(); t->print(); return 0; }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:76:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
printer.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         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...