Submission #690995

#TimeUsernameProblemLanguageResultExecution timeMemory
690995ansgarType Printer (IOI08_printer)C++17
100 / 100
194 ms58428 KiB
#include <bits/stdc++.h> using namespace std; #define vi vector<int> #define vvi vector<vi> #define pii pair<int,int> #define vpii vector<pii> #define vvpii vector<vpii> #define vb vector<bool> #define vc vector<char> #define vvc vector<vc> #define vvb vector<vb>z #define si set<int> #define mii map<int,int> const int MOD=1e9+7; const int N=2e5+1; struct Nodo{ map<char,Nodo*>childs; bool end=false; int depth=1; }; void add(Nodo* Trie,string& word,int index=0){ if((int)word.size()==index){ Trie->end=true; return; } char character=word[index]; if(Trie->childs.find(character)==Trie->childs.end()){ Trie->childs[character]=new Nodo; } add(Trie->childs[character],word,index+1); Trie->depth=max(Trie->depth,Trie->childs[character]->depth+1); } vc sol; int ned=0; void solve(Nodo* Trie){ char last='P'; if(ned and Trie->end)sol.push_back('P'),ned--; int ma=0; for(char e='a';e<='z';e++){ if(Trie->childs.find(e)!=Trie->childs.end()){ if(Trie->childs[e]->depth>ma){ ma=Trie->childs[e]->depth; last=e; } } } //cerr<<Trie->depth<<" "<<last<<endl; for(char e='a';e<='z';e++){ if(e==last)continue; if(Trie->childs.find(e)!=Trie->childs.end()){ //cerr<<char(e)<<endl; if(ned)sol.push_back(e); solve(Trie->childs[e]); if(ned)sol.push_back('-'); } } if(last=='P')return; if(ned)sol.push_back(last); solve(Trie->childs[last]); if(ned)sol.push_back('-'); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; ned=n; Nodo* Root=new Nodo; for(int i=0;i<n;i++){ string s; cin>>s; add(Root,s); } solve(Root); cout<<sol.size()<<"\n"; for(char e : sol)cout<<e<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...