Submission #1312600

#TimeUsernameProblemLanguageResultExecution timeMemory
1312600algoproclubType Printer (IOI08_printer)C++20
20 / 100
248 ms36412 KiB
// UUID: 5fc0b434-98ee-4d76-ba6e-9b400a1d1fcb #include <bits/stdc++.h> using namespace std; struct abctree { abctree* next[26]; bool end; bool inthelongest; abctree() { for (int i = 0; i < 26; i++) next[i] = nullptr; end = false; inthelongest = false; } }; abctree* mainroot; vector<char> out; string longest = ""; void add(abctree* root, string s) { abctree* cur = root; for (char c:s) { int index = c - 'a'; if (!cur -> next[index]) { cur -> next[index] = new abctree; } cur = cur -> next[index]; } cur -> end = true; } void print(abctree* root) { abctree* cur = root; for (int i = 0;i < 26;i++) { if (cur -> next[i] and !cur -> next[i] -> inthelongest) { out.push_back(char(i + 'a')); print(cur -> next[i]); } } for (int i = 0;i < 26;i++) { if (cur -> next[i] and cur -> next[i] -> inthelongest) { out.push_back(char(i + 'a')); print(cur -> next[i]); } } if (cur -> end) { out.push_back('P'); } if (mainroot != cur) { out.push_back('-'); } } int main() { int n;cin >> n; mainroot = new abctree; string s; for (int i = 0;i < n;i++) { cin >> s; if (s.size() > longest.size()) longest = s; add(mainroot, s); } abctree* cur = mainroot; mainroot -> inthelongest = true; for (char c:longest) { cur = cur -> next[c - 'a']; cur -> inthelongest = true; } print(mainroot); cout << out.size() - longest.size() << endl; for (int i = 0;i < out.size() - longest.size();i++) { cout << out[i] << endl; } }
#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...