# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
922062 | 2024-02-05T01:11:29 Z | Syrius | Type Printer (IOI08_printer) | C++14 | 124 ms | 99536 KB |
#include <bits/stdc++.h> using namespace std; //#define int long long #define ll long long #define ff first #define ss second #define pint pair < int , int > #define fast ios_base::sync_with_stdio(NULL); cin.tie(NULL) const int inf = 1e9 + 9; const int mxn = 1e6 + 2; const int mod = 1e9 + 7; struct node { bool ends , path; node *branch[26]; node () { ends = path = 0; for (int i = 0; i < 26; i++) branch[i] = NULL; } }; void insert(node *root , string s) { for (int i = 0; i < s.size(); i++) { int id = s[i] - 'a'; if (root -> branch[id] == NULL) root -> branch[id] = new node(); root = root -> branch[id]; } root -> ends = 1; } void createpath(node *root , string s) { for (int i = 0; i < s.size(); i++) { int id = s[i] - 'a'; root -> branch[id] -> path = 1; root = root -> branch[id]; } } vector < char > ans; void print(node *root) { node *go = NULL; char add; if (root -> ends) ans.push_back('P'); for (int i = 0; i < 26; i++) { if (root -> branch[i] == NULL) continue; if (root -> branch[i] -> path) { go = root -> branch[i]; add = i + 'a'; continue; } ans.push_back(i + 'a'); print(root -> branch[i]); ans.push_back('-'); } if (go != NULL) { ans.push_back(add); print(go); } } int main() { int n; cin >> n; node *root = new node(); string mx; int sz = 0; for (int i = 0; i < n; i++) { string s; cin >> s; insert(root , s); if (s.size() > sz) { mx = s; sz = s.size(); } } createpath(root , mx); print(root); cout << ans.size() << '\n'; for (int i = 0; i < ans.size(); i++) cout << ans[i] << '\n'; return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 1 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 428 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 440 KB | Output is correct |
2 | Correct | 0 ms | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 1116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1884 KB | Output is correct |
2 | Correct | 3 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 10 ms | 5976 KB | Output is correct |
2 | Correct | 15 ms | 12632 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 24 ms | 14800 KB | Output is correct |
2 | Correct | 8 ms | 3416 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 54 ms | 36616 KB | Output is correct |
2 | Correct | 104 ms | 83824 KB | Output is correct |
3 | Correct | 65 ms | 43212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 28808 KB | Output is correct |
2 | Correct | 124 ms | 99536 KB | Output is correct |
3 | Correct | 68 ms | 49100 KB | Output is correct |
4 | Correct | 105 ms | 94096 KB | Output is correct |