Submission #640044

#TimeUsernameProblemLanguageResultExecution timeMemory
640044a_aguiloType Printer (IOI08_printer)C++14
90 / 100
1095 ms100456 KiB
#include <bits/stdc++.h> using namespace std; struct Trie{ struct Trie *child[26]; char letra; bool endOfWord,longest; }; struct Trie *createNode(char letra){ struct Trie *nodo = new Trie; memset(nodo->child, NULL, sizeof(nodo->child)); nodo->endOfWord = false; nodo->longest = false; nodo->letra = letra; return nodo; } void insert(struct Trie *root, string key, bool masLarga){ struct Trie *curr = root; for(int i=0; i<(int)key.size(); i++){ int index = key[i] - 'a'; if(curr->child[index] == NULL){ curr->child[index] = createNode(key[i]); } curr = curr->child[index]; if(masLarga) curr->longest = true; } curr->endOfWord = true; } int counting(Trie *root){ Trie *curr = root; int cont = 2; if(curr->longest){ cont--; } for(int i=0; i<26; i++){ if(curr->child[i] != NULL){ Trie *sig = curr->child[i]; cont += counting(sig); } } return cont; } void printing(Trie *root){ Trie *curr = root; //cout << curr->letra << endl; if(curr->endOfWord){ cout << 'P' << endl; } Trie *seguimos = root; for(int i=0; i<26; i++){ if(curr->child[i] != NULL){ //cout << sizeof(*(curr->child[i])) << " " << sizeof(Trie) << endl; //if(sizeof(*(curr->child[i])) == sizeof(Trie)){ Trie *sig = curr->child[i]; if(sig->longest){ seguimos = sig; }else{ cout << sig->letra << endl; printing(sig); } } } if(seguimos != root){ //cout << sizeof(*seguimos) << " " << sizeof(Trie) << endl; //if(sizeof(*seguimos) == sizeof(Trie)){ cout << seguimos->letra << endl; printing(seguimos); return; } if(!curr->longest) cout << '-' << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; struct Trie *root = createNode('0'); root->longest = true; vector<string> v(n); pair<int,int> longest; longest.first = 1; longest.second = 0; for(int i=0; i<n; i++){ string s; cin >> s; v[i] = s; if((int)s.size() > longest.first){ longest.first = s.size(); longest.second = i; } } for(int i=0; i<n; i++){ if(i == longest.second){ insert(root,v[i],true); }else insert(root,v[i],false); } //cout << sizeof(Trie) << endl; //cout << sizeof(*root) << endl; cout << counting(root)+n-1 << endl; printing(root); }

Compilation message (stderr)

printer.cpp: In function 'Trie* createNode(char)':
printer.cpp:12:25: warning: passing NULL to non-pointer argument 2 of 'void* memset(void*, int, size_t)' [-Wconversion-null]
   12 |     memset(nodo->child, NULL, sizeof(nodo->child));
      |                         ^~~~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++config.h:518,
                 from /usr/include/c++/10/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from printer.cpp:1:
/usr/include/x86_64-linux-gnu/bits/string_fortified.h:59:1: note:   declared here
   59 | __NTH (memset (void *__dest, int __ch, size_t __len))
      | ^~~~~
#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...