# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094532 | 2024-09-29T19:41:33 Z | vjudge1 | Type Printer (IOI08_printer) | C++17 | 123 ms | 106436 KB |
// #pragma GCC optimize ("O3") // #pragma GCC optimize ("unroll-loops") // #pragma comment(linker, "/STACK:2000000") #include<bits/stdc++.h> using namespace std; #define ll long long #define int long long #define ld long double #define endl "\n" #define FOCUS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); void Go() { ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } ll node=1; struct trienode { trienode* child[26]; bool wordEnd; ll cur_node; ll mx; trienode() { wordEnd=false; for(auto &it:child)it= nullptr; cur_node=0; } }; struct Trie { trienode* root=new trienode(); void insert(string s) { trienode* cur=root; ll cnt=0; for(auto it:s) { if(cur->child[it-'a']== nullptr) cur->child[it-'a']=new trienode (),cur->child[it-'a']->cur_node=node++; cur=cur->child[it-'a']; cur->mx=max(cur->mx,(int)s.size()-cnt++); } cur->wordEnd=true; } bool search(string s) { trienode*cur=root; for(auto it:s) { if(cur->child[it-'a']== nullptr)return false; cur=cur->child[it-'a']; } return cur->wordEnd; } }; int depth[25001]; vector<char>ans; void dfs(trienode* cur) { vector<pair<ll,ll>>temp; for(int i=0;i<=25;i++) { if(cur->child[i]!= nullptr) temp.push_back({cur->child[i]->mx,i}); } sort(temp.begin(),temp.end()); for(auto it:temp) { ans.push_back((char)(it.second+'a')); if(cur->child[it.second]->wordEnd) ans.push_back('P'); dfs(cur->child[it.second]); ans.push_back('-'); } } signed main() { //Go(); ll n; cin>>n; Trie trie; for(int i=0;i<n;i++) { string x; cin>>x; trie.insert(x); } dfs(trie.root); while (ans.size()&&ans.back()=='-')ans.pop_back(); cout<<ans.size()<<endl; for(auto it:ans) cout<<it<<endl; return 0; }
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 | 0 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 | 344 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 | 1 ms | 348 KB | Output is correct |
2 | Correct | 2 ms | 1116 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 1884 KB | Output is correct |
2 | Correct | 3 ms | 2396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 8 ms | 6232 KB | Output is correct |
2 | Correct | 16 ms | 13404 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 20 ms | 15832 KB | Output is correct |
2 | Correct | 8 ms | 3676 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 49 ms | 38872 KB | Output is correct |
2 | Correct | 113 ms | 89544 KB | Output is correct |
3 | Correct | 62 ms | 46288 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 40 ms | 30416 KB | Output is correct |
2 | Correct | 123 ms | 106436 KB | Output is correct |
3 | Correct | 65 ms | 52428 KB | Output is correct |
4 | Correct | 114 ms | 100528 KB | Output is correct |