# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
440537 | 2021-07-02T11:43:22 Z | dxz05 | Type Printer (IOI08_printer) | C++14 | 1000 ms | 69404 KB |
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; #define SZ(x) (int)(x).size() const int MAXN = 6e5 + 3e2; string str[MAXN]; int next_free = 2; int trie[MAXN][27]; bool term[MAXN]; void add(string &s){ int v = 1; for (int i = 0; i < s.size(); i++){ int x = s[i] - 'a'; if (trie[v][x] == 0) trie[v][x] = next_free++; v = trie[v][x]; } term[v] = true; } int idx = 0; string gs; void sort(int v){ if (term[v]) str[++idx] = gs; for (int i = 0; i <= 26; i++){ if (trie[v][i] != 0){ gs += char('a' + i); sort(trie[v][i]); gs.pop_back(); } } } int main(){ ios_base::sync_with_stdio(false); int n; cin >> n; int ind = 0; for (int i = 1; i <= n; i++){ cin >> str[i]; if (str[i].size() > str[ind].size()) ind = i; } string longest = str[ind]; for (int i = 1; i <= n; i++){ int j = 0; while (j < str[i].size() && j < longest.size() && str[i][j] == longest[j]) j++; if (j) str[i] = string(j, '{') + str[i]; add(str[i]); } sort(1); vector<char> ans; for (int it = 1; it <= n; it++){ int j = 0; while (j < str[it].size() && str[it][j] == '{') j++; str[it].erase(0, j); string s = str[it], t = str[it - 1]; if (SZ(t) > SZ(s)){ int need = SZ(t) - SZ(s); while (need--) ans.push_back('-'); t.resize(s.size()); } int cnt = 0; for (int i = 0; i < min(SZ(t), SZ(s)); i++){ if (t[i] == s[i]) cnt++; else break; } int need = max(0, SZ(t) - cnt); while (need--){ ans.push_back('-'); } for (int i = cnt; i < s.size(); i++){ ans.push_back(s[i]); } ans.push_back('P'); } cout << ans.size() << endl; for (char c : ans) cout << c << endl; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 19020 KB | Output is correct |
2 | Correct | 11 ms | 19036 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 19088 KB | Output is correct |
2 | Correct | 11 ms | 19080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 19128 KB | Output is correct |
2 | Correct | 11 ms | 19020 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 19020 KB | Output is correct |
2 | Correct | 11 ms | 19048 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 19148 KB | Output is correct |
2 | Correct | 22 ms | 19532 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 33 ms | 19916 KB | Output is correct |
2 | Correct | 38 ms | 20068 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 101 ms | 22092 KB | Output is correct |
2 | Correct | 210 ms | 25368 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 224 ms | 26404 KB | Output is correct |
2 | Correct | 73 ms | 20812 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 544 ms | 37760 KB | Output is correct |
2 | Execution timed out | 1098 ms | 61560 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 439 ms | 33252 KB | Output is correct |
2 | Execution timed out | 1101 ms | 69404 KB | Time limit exceeded |
3 | Halted | 0 ms | 0 KB | - |