Submission #1003423

#TimeUsernameProblemLanguageResultExecution timeMemory
1003423fryingducType Printer (IOI08_printer)C++17
100 / 100
97 ms98568 KiB
#include "bits/stdc++.h" using namespace std; const int maxn = 25005; int n; string del; struct trie { int total_nodes; struct node { node *child[26]; bool exist; node() { exist = 0; for(int i = 0; i < 26; ++i) { child[i] = nullptr; } } } *root; trie() { total_nodes = 0; root = new node(); } void add(string &s) { node *p = root; for(int i = 0; i < (int)s.size(); ++i) { int c = s[i] - 'a'; if(p->child[c] == nullptr) { p->child[c] = new node(); ++total_nodes; } p = p->child[c]; } p->exist = 1; } void dfs(int depth, node *p, bool flag) { if(p->exist) { cout << 'P' << '\n'; } for(int i = 0; i < 26; ++i) { if(p->child[i] == nullptr || (flag and i == del[depth] - 'a')) continue; cout << char(i + 'a') << '\n'; dfs(depth + 1, p->child[i], 0); } if(flag and depth < (int)del.size() and p->child[del[depth] - 'a'] != nullptr) { cout << del[depth] << '\n'; dfs(depth + 1, p->child[del[depth] - 'a'], 1); return; } if(!flag) cout << "-\n"; } void dfs() { dfs(0, root, 1); } } t; void solve() { cin >> n; string s; for(int i = 1; i <= n; ++i) { cin >> s; t.add(s); if((int)s.size() > (int)del.size()) { del = s; } } cout << t.total_nodes * 2 + n - (int)del.size() << '\n'; t.dfs(); } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); solve(); return 0; }
#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...