Submission #120423

#TimeUsernameProblemLanguageResultExecution timeMemory
120423mielloType Printer (IOI08_printer)C++11
30 / 100
89 ms36472 KiB
#include <bits/stdc++.h> #define ii pair<int,int> using namespace std; struct node{ struct node *alpha[26]; bool endofword , el; }; int num[26]; vector<ii> v; queue<char> q; int word , n; void backtrack(node *h , int now){ q.push('a' + now); if(h->el){ q.push('P'); word++; } for(int i = 0 ; i < 26 ; i++){ if(h->alpha[i] != NULL){ backtrack(h->alpha[i] , i); } } if(word != n)q.push('-'); } node* getnew(){ node *x = new node; x->endofword = 0; x->el = 0; for(int i = 0 ; i < 26 ; i++){ x->alpha[i] = NULL; } return x; } int getsz(node *p){ int sz = 1; if(p->endofword){ return 1; } for(int i = 0 ; i < 26 ; i++){ if(p->alpha[i] != NULL){ sz += getsz(p->alpha[i]); } } return sz; } int main(){ scanf("%d",&n); node *head = getnew(); for(int i = 0 ; i < n ; i++){ string s; cin >> s; int l = s.size(); node *x; x = head; for(int j = 0 ; j < l ; j++){ if(x->alpha[s[j] - 'a'] == NULL){ x->alpha[s[j] - 'a'] = getnew(); x->endofword = 0; x->alpha[s[j] - 'a']->endofword = 1; } x = x->alpha[s[j] - 'a']; } x->el = 1; } for(int i = 0 ; i < 26 ; i++){ if(head->alpha[i] != NULL){ v.emplace_back(getsz(head->alpha[i]) , i); } } sort(v.begin() , v.end()); for(auto i : v){ int u = i.second; backtrack(head->alpha[u] , u); } printf("%d\n",q.size()); while(q.size()){ printf("%c\n",q.front()); q.pop(); } }

Compilation message (stderr)

printer.cpp: In function 'int main()':
printer.cpp:82:24: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::queue<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n",q.size());
                ~~~~~~~~^
printer.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&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...