Submission #498596

#TimeUsernameProblemLanguageResultExecution timeMemory
498596Hi_Im_Not_Meo_MeoType Printer (IOI08_printer)C++14
100 / 100
128 ms113252 KiB
#include"bits/stdc++.h" #define f(i,j,k) for(int i=j;i<=k;i++) #define pb push_back const int N = 3e4; using namespace std; int n; string s, last; vector <char> ans; struct Node{ int ed; Node* child[30]; Node(){ ed = 0; f(i,0,29) child[i] = nullptr; } }; struct Trie{ Node *root; Trie(){ root = new Node;} void __up(string S){ Node *it = root; for(auto ii : S){ int j = (int) ii - 'a'; if(!it->child[j]) it->child[j] = new Node; it = it->child[j]; } it->ed = 1; } void dfs(Node* i1, int len, int ok){ int Alast = ok ? (int) last[len] - 'a' : -1; if(i1->ed == 1) ans.pb('P'); f(i,0,25){ if(i == Alast || !i1->child[i]) continue; ans.pb('a'+i); dfs(i1->child[i],len+1,0); ans.pb('-'); } if(ok){ ans.pb(last[len]); if(len == last.size() - 1) ans.pb('P'); else dfs(i1->child[Alast],len+1,1); } } }lxv; main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n; f(i,1,n){ cin>>s; lxv.__up(s); if(s.size() > last.size()) last = s; } lxv.dfs(lxv.root,0,1); cout<<ans.size()<<'\n'; for(auto i: ans) cout<<i<<'\n'; }

Compilation message (stderr)

printer.cpp: In member function 'void Trie::dfs(Node*, int, int)':
printer.cpp:43:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   43 |    if(len == last.size() - 1) ans.pb('P');
      |       ~~~~^~~~~~~~~~~~~~~~~~
printer.cpp: At global scope:
printer.cpp:51:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   51 | main(){
      | ^~~~
#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...