# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
673786 | 2022-12-22T03:23:27 Z | chanhchuong123 | Type Printer (IOI08_printer) | C++14 | 56 ms | 34916 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); dp[0]++; while (dp[0]--) res.pop_back(); cout << res.size() << '\n'; for (char &c: res) cout << c << '\n'; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 11988 KB | Output is correct |
2 | Correct | 6 ms | 11988 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 12084 KB | Output is correct |
2 | Correct | 6 ms | 12080 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 11980 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 6 ms | 12076 KB | Output is correct |
2 | Incorrect | 9 ms | 11988 KB | didn't print every word |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 7 ms | 12116 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 13012 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 13 ms | 15572 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 31 ms | 21212 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 56 ms | 34916 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 50 ms | 29676 KB | didn't print every word |
2 | Halted | 0 ms | 0 KB | - |