# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1094528 | 2024-09-29T19:34:31 Z | vjudge1 | Type Printer (IOI08_printer) | C++17 | 4 ms | 348 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')); dfs(cur->child[it.second]); if(cur->child[it.second]->wordEnd) ans.push_back('P'); 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 | Incorrect | 4 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 3 ms | 344 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 344 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 2 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Incorrect | 4 ms | 348 KB | Unexpected end of file - int32 expected |
2 | Halted | 0 ms | 0 KB | - |