Submission #818179

#TimeUsernameProblemLanguageResultExecution timeMemory
818179Sir_Ahmed_ImranType Printer (IOI08_printer)C++17
30 / 100
159 ms84476 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define li long int #define ld long double #define append push_back #define add insert #define nl "\n" #define ff first #define ss second #define pii pair<int,int> #define pic pair<int,char> #define all(x) (x).begin(),(x).end() #define sum(a) accumulate(all(a),0) #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL) #define terminator main #define MAXN 100001 class TrieNode { public: bool prt; TrieNode* nxt[26]; TrieNode(){ for(int i=prt=0;i<26;i++) nxt[i]=NULL; } }; class Trie{ public: TrieNode* root; Trie(){ root=new TrieNode(); } void insert(string a){ int m; TrieNode* x=root; for(int i=0;i<a.size();i++){ m=a[i]-'a'; if(!x->nxt[m]) x->nxt[m]=new TrieNode(); x=x->nxt[m]; } x->prt=1; } vector<char> dfs(TrieNode* x,vector<char> v){ vector<pair<int,vector<char>>> a; for(int i=0;i<26;i++){ if(!x->nxt[i]) continue; vector<char> u; u.append('a'+i); if((x->nxt[i])->prt) u.append('P'); u=dfs(x->nxt[i],u); u.append('-'); a.append({u.size(),u}); } sort(all(a)); for(auto& i:a) for(auto& j:i.ss) v.append(j); return v; } }; void solve(){ string a; int n,m,o,p,q; Trie x; cin>>n; for(int i=0;i<n;i++){ cin>>a; x.insert(a); } vector<char> v; v=x.dfs(x.root,v); m=v.size(); while(m && v[m-1]=='-') m--; cout<<m<<nl; for(int i=0;i<m;i++) cout<<v[i]<<nl; } int terminator(){ L0TA; solve(); return 0; }

Compilation message (stderr)

printer.cpp: In member function 'void Trie::insert(std::string)':
printer.cpp:37:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
printer.cpp: In function 'void solve()':
printer.cpp:66:13: warning: unused variable 'o' [-Wunused-variable]
   66 |     int n,m,o,p,q;
      |             ^
printer.cpp:66:15: warning: unused variable 'p' [-Wunused-variable]
   66 |     int n,m,o,p,q;
      |               ^
printer.cpp:66:17: warning: unused variable 'q' [-Wunused-variable]
   66 |     int n,m,o,p,q;
      |                 ^
#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...