# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
535858 | 2022-03-11T14:41:01 Z | cig32 | Type Printer (IOI08_printer) | C++17 | 180 ms | 65404 KB |
#include <iostream> #include <cstdlib> #include <cstdio> #include <fstream> #include <algorithm> #include <string> #include <utility> #include <vector> #include <queue> using namespace std; vector<int> lets[500000]; bool endb[500000] = {}; int length[500000] = {}, sz = 0; vector<char> ans; void add(int c, int i, string s){ if (i == s.length()){ endb[c] = true; return; } int l = int(s[i])-97; if (lets[c][l] == 0){ vector<int> t; t.resize(26, 0); lets[sz] = t; lets[c][l] = sz; sz++; } add(lets[c][l], i+1, s); length[c] = max(length[lets[c][l]]+1, length[c]); } void solve(long c){ if (endb[c]){ ans.push_back('P'); } bool lu = false; int dl = -1; for (int i = 0; i < 26; i++){ if (lets[c][i] != 0){ if (!lu && length[lets[c][i]] == length[c]-1){ lu = true; dl = i; } else { ans.push_back(char(i+97)); solve(lets[c][i]); ans.push_back('-'); } } } if (dl > -1){ ans.push_back(char(dl+97)); solve(lets[c][dl]); ans.push_back('-'); } } int main(){ int n; cin >> n; vector<int> t; t.resize(26, 0); lets[sz] = t; sz++; for (int i = 0; i < n; i++){ string s; cin >> s; add(0, 0, s); } solve(0); int count = ans.size(); while (ans[count-1] == '-'){ count--; } printf("%d\n", count); for (int i = 0; i < count-1; i++){ printf("%c\n", ans[i]); } printf("%c", ans[count-1]); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 11988 KB | Output is correct |
2 | Correct | 8 ms | 12016 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 12048 KB | Output is correct |
2 | Correct | 7 ms | 11988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11988 KB | Output is correct |
2 | Correct | 7 ms | 11988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 12052 KB | Output is correct |
2 | Correct | 7 ms | 11988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12116 KB | Output is correct |
2 | Correct | 8 ms | 12436 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 13 ms | 12884 KB | Output is correct |
2 | Correct | 12 ms | 13012 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 15084 KB | Output is correct |
2 | Correct | 26 ms | 18672 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 30 ms | 19876 KB | Output is correct |
2 | Correct | 20 ms | 13780 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 70 ms | 31600 KB | Output is correct |
2 | Correct | 149 ms | 56872 KB | Output is correct |
3 | Correct | 96 ms | 35216 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 59 ms | 27384 KB | Output is correct |
2 | Correct | 180 ms | 65404 KB | Output is correct |
3 | Correct | 109 ms | 38348 KB | Output is correct |
4 | Correct | 151 ms | 62476 KB | Output is correct |