# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673791 | 2022-12-22T03:26:44 Z | chanhchuong123 | Type Printer (IOI08_printer) | C++14 | 51 ms | 34740 KB |
#include <bits/stdc++.h> using namespace std; #define task "C" #define fi first #define se second #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int MAX = 500000; int n; string s; int dp[MAX]; int numNode; char c[MAX]; int nxt[MAX][26]; vector<int> adj[MAX]; void add(string s) { int p = 0; for (int i = 0; i < s.size(); ++i) { int LOVE = s[i] - 'a'; if (nxt[p][LOVE] == 0) { c[numNode + 1] = s[i]; nxt[p][LOVE] = ++numNode; adj[p].push_back(numNode); } p = nxt[p][LOVE]; } } void dfs(int u) { for (int v: adj[u]) { dfs(v); maxi(dp[u], dp[v] + 1); } } string res; void re_dfs(int u) { if (adj[u].empty()) { res += 'P'; res += '-'; return; } for (int v: adj[u]) { res += c[v]; re_dfs(v); } res += '-'; } main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; for (int i = 0; i < n; ++i) { cin >> s; add(s); } dfs(0); for (int i = 0; i <= numNode; ++i) { sort(all(adj[i]), [&](int u, int v) { return dp[u] < dp[v]; }); } re_dfs(0); while (res.back() != 'P') res.pop_back(); cout << res.size() << '\n'; for (char &c: res) cout << c << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 11988 KB | Output is correct |
2 | Correct | 7 ms | 12072 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Correct | 7 ms | 11988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 6 ms | 11988 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Incorrect | 8 ms | 11988 KB | didn't print every word |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 12116 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 9 ms | 13024 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 14 ms | 15572 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 25 ms | 21092 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 51 ms | 34740 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 47 ms | 29472 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |