# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
746178 | 2023-05-21T16:55:30 Z | khulegub | Type Printer (IOI08_printer) | C++17 | 22 ms | 21460 KB |
#include <bits/stdc++.h> using namespace std; const int N = 100000; /** Node count*/ int k = 1; int to[N][26]; char a[N]; vector<char> ans; void dfs(int u) { if (u > 0) ans.push_back(a[u]); bool is_leaf = true; for (int i = 0; i < 26; i++) { if (to[u][i] != -1) { is_leaf = false; dfs(to[u][i]); } } if (is_leaf) { ans.push_back('P'); } ans.push_back('-'); } int main() { int n; cin >> n; memset(to, -1, sizeof to); for (int i = 0; i < n; i++) { string s; cin >> s; int curr = 0; for (int j = 0; j < s.length(); j++) { int c = s[j] - 'a'; if (to[curr][c] == -1) { // Create a new node. to[curr][c] = k; k++; } a[to[curr][c]] = s[j]; curr = to[curr][c]; } } dfs(0); vector<pair<int, string> > v; string last = ""; int longest = -1; int p_count = 0; for (int i = 0; i < ans.size(); i++) { if (ans[i] == '-') { if (last != "") { v.push_back({1, last}); last = ""; } else { v.back().first++; longest = max(longest, v.back().first); } } else { if (ans[i] == 'P') { p_count++; } last += (ans[i]); } } sort(v.begin(), v.end()); reverse(v.begin(), v.end()); cout << ans.size() - longest - p_count << endl; for (int i = 0; i < v.size(); i++) { for (int j = 0; j < v[i].second.length(); j++) { cout << v[i].second[j] << '\n'; } if (i < v.size() -1) { for (int j = 0; j < v[i].first - 1; j++) { cout << '-' << '\n'; } } } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 10452 KB | Expected EOF |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 10452 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 10452 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 10452 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 5 ms | 10452 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 8 ms | 10580 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 11 ms | 10940 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 22 ms | 11552 KB | printed invalid word |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 19 ms | 21460 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 20 ms | 21356 KB | Execution killed with signal 11 |
2 | Halted | 0 ms | 0 KB | - |