# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
551227 | 2022-04-20T06:06:46 Z | Pherokung | Type Printer (IOI08_printer) | C++14 | 117 ms | 51624 KB |
#include<bits/stdc++.h> using namespace std; #define N 25000 int n,l,sz=0,cnt=0,mx_l,st; char s[25]; vector<char> ans; struct node{ int nxt[26], val, mx; } trie[1000005]; void dfs(int pos){ if(cnt == n) return; vector<pair<int,int> > v; if(trie[pos].val == 1 && cnt != n) ans.push_back('P'), cnt++; for(int i=0;i<=25;i++) if(trie[pos].nxt[i] && cnt != n) v.push_back({trie[trie[pos].nxt[i]].mx,i}); sort(v.begin(),v.end()); for(auto x : v) ans.push_back(x.second + 'a'), dfs(trie[pos].nxt[x.second]); if(cnt != n)ans.push_back('-'); } int main(){ scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s",s+1); l = strlen(s+1); int now = 0; for(int j=1;j<=l;j++){ int idx = s[j] - 'a'; if(!trie[now].nxt[idx]) trie[now].nxt[idx] = ++sz; trie[now].mx = max(trie[now].mx,l); now = trie[now].nxt[idx]; } trie[now].val = 1; } dfs(0); printf("%d\n",ans.size()); for(auto x : ans) printf("%c\n",x); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 212 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 212 KB | Output is correct |
2 | Correct | 1 ms | 308 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 340 KB | Output is correct |
2 | Correct | 3 ms | 724 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 1108 KB | Output is correct |
2 | Correct | 4 ms | 1336 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 9 ms | 3284 KB | Output is correct |
2 | Correct | 15 ms | 6628 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 17 ms | 7760 KB | Output is correct |
2 | Correct | 9 ms | 1928 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 47 ms | 19120 KB | Output is correct |
2 | Correct | 103 ms | 43416 KB | Output is correct |
3 | Correct | 53 ms | 22576 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 15024 KB | Output is correct |
2 | Correct | 117 ms | 51624 KB | Output is correct |
3 | Correct | 60 ms | 25528 KB | Output is correct |
4 | Correct | 108 ms | 48700 KB | Output is correct |