# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
985476 | 2024-05-17T23:40:43 Z | PagodePaiva | Type Printer (IOI08_printer) | C++17 | 40 ms | 36048 KB |
#include<bits/stdc++.h> using namespace std; int n; int cnt; vector <char> v; struct Trie{ Trie *child[26]; int prof, tam; Trie(){ prof = -1; tam = 0; for(int i = 0;i < 26;i++) child[i] = NULL; } void add(string s, int pos){ if(pos == s.size()) return; if(!child[s[pos]-'a']) child[s[pos]-'a'] = new Trie(); child[s[pos]-'a']->add(s, pos+1); if(prof == -1 or child[s[pos]-'a']->tam+1>child[prof]->tam){ prof = s[pos]-'a'; tam = child[s[pos]-'a']->tam+1; } return; } void query(int typ){ bool aux = true; for(int i = 0;i < 26;i++) if(child[i]) aux = false; if(aux){ v.push_back('P'); cnt++; if(cnt == n){ cout << v.size() << '\n'; for(auto x : v){ cout << x << '\n'; } exit(0); } return; } if(typ == 0){ for(int i = 0;i < 26;i++){ if(child[i] and i != prof){ v.push_back(i+'a'); child[i]->query(1); v.push_back('-'); } } if(prof == -1) return; v.push_back(prof+'a'); child[prof]->query(0); return; } else{ for(int i = 0;i < 26;i++){ if(child[i]){ v.push_back(i+'a'); child[i]->query(1); v.push_back('-'); } } } } } trie; int main(){ cin >> n; for(int i = 0;i < n;i++){ string s; cin >> s; trie.add(s, 0); } trie.query(0); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 0 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Incorrect | 0 ms | 348 KB | Unexpected end of file - int32 expected |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 1 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 1884 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 5724 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 15 ms | 14684 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 40 ms | 36048 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 34 ms | 28112 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |