Submission #387396

#TimeUsernameProblemLanguageResultExecution timeMemory
387396stefantagaType Printer (IOI08_printer)C++14
100 / 100
215 ms106656 KiB
#include <bits/stdc++.h> using namespace std; struct trie { int nr,marime; trie *v[28]; trie () { int j; nr=0; marime=0; for (j=0;j<=26;j++) { v[j]=nullptr; } } } *tree = new trie ; void adauga (trie *tree, char *s) { if (*s==0) { tree->nr++; return; } int loc=(*s-'a'); if (tree->v[loc]==nullptr) { tree->v[loc]=new trie; } adauga(tree->v[loc],s+1); } vector <char> op; void dfs1(trie *tree) { int j; tree->marime=1; for (j=0;j<=26;j++) { if (tree->v[j]!=nullptr) { dfs1(tree->v[j]); tree->marime=max(tree->marime,tree->v[j]->marime+1); } } } void dfs2(trie *tree) { int j; for (j=1;j<=tree->nr;j++) { op.push_back('P'); } vector <pair <int,int> > val; for (j=0;j<=26;j++) { if (tree->v[j]!=nullptr) { val.push_back({tree->v[j]->marime,j}); } } sort (val.begin(),val.end()); for (j=0;j<val.size();j++) { op.push_back((char)(val[j].second+97)); dfs2(tree->v[val[j].second]); } op.push_back('-'); } int n,i,j; char s[25]; int main() { ios_base :: sync_with_stdio(false); cin.tie(0); #ifdef HOME ifstream cin("date.in"); ofstream cout("date.out"); #endif // HOME cin>>n; for (i=1;i<=n;i++) { cin>>s; adauga(tree,s); } dfs1(tree); dfs2(tree); while (op.size()>0&&op[op.size()-1]=='-') { op.pop_back(); } cout<<op.size()<<'\n'; for (j=0;j<op.size();j++) { cout<<op[j]<<'\n'; } return 0; }

Compilation message (stderr)

printer.cpp: In function 'void dfs2(trie*)':
printer.cpp:63:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (j=0;j<val.size();j++)
      |              ~^~~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:94:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |     for (j=0;j<op.size();j++)
      |              ~^~~~~~~~~~
#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...