# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
915025 | 2024-01-23T08:10:08 Z | allin27x | Type Printer (IOI08_printer) | C++17 | 138 ms | 99640 KB |
#include <bits/stdc++.h> using namespace std; struct prtr{ prtr* r[26] {nullptr}; bool last = 0; bool end = 0; }; vector<char> ans; void add(string s, prtr* root){ for (int i=0; i<s.size(); i++){ if (!(root -> r[s[i]-'a'])) root->r[s[i]-'a'] = new prtr(); root = root->r[s[i]-'a']; } root -> end = 1; } void make_last(string s, prtr* root){ for (int i=0; i<s.size(); i++){ if (!(root -> r[s[i]-'a'])) root->r[s[i]-'a'] = new prtr(); root = root->r[s[i]-'a']; root -> last = 1; } } void dfs(prtr* root){ int l = -1; if (root->end) ans.push_back('P'); for (int i=0; i<26; i++){ if (!root->r[i]) continue; if (root->r[i]->last) {l=i; continue;} ans.push_back('a'+i); dfs(root->r[i]); ans.push_back('-'); } if (l==-1) return; ans.push_back('a'+l); dfs(root->r[l]); } int main(){ int n; cin>>n; prtr* root = new prtr(); int mxsz = 0; string mw = ""; while (n--){ string s; cin>>s; if (s.size()>=mxsz) mxsz = s.size(), mw = s; add(s, root); } make_last(mw,root); dfs(root); cout<<ans.size()<<'\n'; for (int i=0; i<ans.size(); i++){ cout<<ans[i]<<'\n'; } }
Compilation message
# | 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 | 344 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 348 KB | Output is correct |
2 | Correct | 0 ms | 348 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 | 1880 KB | Output is correct |
2 | Correct | 3 ms | 2140 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 7 ms | 5976 KB | Output is correct |
2 | Correct | 16 ms | 12480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 19 ms | 14812 KB | Output is correct |
2 | Correct | 9 ms | 3472 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 36704 KB | Output is correct |
2 | Correct | 115 ms | 83656 KB | Output is correct |
3 | Correct | 61 ms | 43316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 43 ms | 28632 KB | Output is correct |
2 | Correct | 138 ms | 99640 KB | Output is correct |
3 | Correct | 73 ms | 49104 KB | Output is correct |
4 | Correct | 112 ms | 94156 KB | Output is correct |