# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
396645 | 2021-04-30T14:01:51 Z | peuch | Type Printer (IOI08_printer) | C++17 | 82 ms | 41868 KB |
#include<bits/stdc++.h> using namespace std; const int MAXN = 25000; int n; vector<int> ar[MAXN * 26]; int marc[MAXN * 26]; int letras[MAXN * 26][30]; char v[MAXN * 26]; int cnt = 0; vector<string> palavras; vector<char> ans; void dfs(int cur, int pai){ if(marc[cur]) ans.push_back('P'); for(int i = 0; i < ar[cur].size(); i++){ int viz = ar[cur][i]; if(viz == pai) continue; ans.push_back(v[viz]); dfs(viz, cur); ans.push_back('-'); } } bool cmp(string a, string b){ return a.size() < b.size(); } int main(){ scanf("%d", &n); for(int i = 0; i < n; i++){ string aux; cin >> aux; palavras.push_back(aux); } sort(palavras.begin(), palavras.end(), cmp); for(int i = 0; i < n; i++){ int cur = 0; for(int j = 0; j < palavras[i].size(); j++){ if(letras[cur][palavras[i][j] - 'a'] == 0) { letras[cur][palavras[i][j] - 'a'] = ++cnt; ar[cur].push_back(cnt); v[cnt] = palavras[i][j]; } cur = letras[cur][palavras[i][j] - 'a']; } marc[cur] = 1; } dfs(0, 0); while(ans[ans.size() - 1] == '-') ans.pop_back(); printf("%d\n", ans.size()); for(int i = 0; i < ans.size(); i++) printf("%c\n", ans[i]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 15564 KB | Output is correct |
2 | Correct | 10 ms | 15576 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 15488 KB | Output is correct |
2 | Incorrect | 11 ms | 15564 KB | Output isn't correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 15564 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 15564 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 10 ms | 15564 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 12 ms | 16588 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 21 ms | 19640 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 38 ms | 25916 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 82 ms | 41868 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 72 ms | 36080 KB | Output isn't correct |
2 | Halted | 0 ms | 0 KB | - |