Submission #369411

#TimeUsernameProblemLanguageResultExecution timeMemory
369411NachoLibreType Printer (IOI08_printer)C++17
100 / 100
177 ms98704 KiB
#include <bits/stdc++.h> #define sz(a) ((int)a.size()) using namespace std; struct cac { cac *a[26]; int l; bool p; cac() : p(0), l(26) { for(int i = 0; i < 26; ++i) a[i] = NULL; } } *rt = new cac(); int n, w; string s, l; void G(cac *x) { for(int i = 0; i < 26; ++i) { if(i != x->l && x->a[i] != NULL) { cout << (char)('a' + i) << "\n"; if(x->a[i]->p) cout << "P\n"; G(x->a[i]); cout << "-\n"; } } if(x->l != 26) { cout << (char)('a' + x->l) << "\n"; if(x->a[x->l]->p) cout << "P\n"; G(x->a[x->l]); } } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n; for(int i = 0; i < n; ++i) { cin >> s; if(sz(s) > sz(l)) l = s; cac *dg = rt; for(int j = 0; j < sz(s); ++j) { if(dg->a[s[j] - 'a'] == NULL) { w += 2; dg->a[s[j] - 'a'] = new cac(); } dg = dg->a[s[j] - 'a']; } dg->p = 1; } { cac *dg = rt; for(int i = 0; i < sz(l); ++i) { dg->l = l[i] - 'a'; dg = dg->a[dg->l]; } } cout << w - sz(l) + n << "\n"; G(rt); return 0; }

Compilation message (stderr)

printer.cpp: In constructor 'cac::cac()':
printer.cpp:8:7: warning: 'cac::p' will be initialized after [-Wreorder]
    8 |  bool p;
      |       ^
printer.cpp:7:6: warning:   'int cac::l' [-Wreorder]
    7 |  int l;
      |      ^
printer.cpp:9:2: warning:   when initialized here [-Wreorder]
    9 |  cac() : p(0), l(26) {
      |  ^~~
#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...