Submission #819014

#TimeUsernameProblemLanguageResultExecution timeMemory
819014Sir_Ahmed_ImranType Printer (IOI08_printer)C++17
100 / 100
110 ms98548 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: int z; bool prt; TrieNode* nxt[26]; TrieNode(){ for(int i=prt=z=0;i<26;i++) nxt[i]=NULL; } }; class Trie{ public: TrieNode* root; int siz; Trie(){ siz=0; 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]){ siz++; x->nxt[m]=new TrieNode(); } x=x->nxt[m]; if(a.size()>x->z) x->z=a.size(); } x->prt=1; } void dfs(TrieNode* x){ vector<pii> v; for(int i=0;i<26;i++) if(x->nxt[i]) v.append({x->nxt[i]->z,i}); sort(all(v)); for(auto& i:v){ siz--; cout<<char(i.ss+'a')<<nl; if(x->nxt[i.ss]->prt){ siz--; cout<<'P'<<nl; } dfs(x->nxt[i.ss]); if(siz>0) cout<<'-'<<nl; siz--; } } }; void solve(){ string a; int n,m,o,p,q; Trie x; cin>>n; for(int i=m=0;i<n;i++){ cin>>a; x.insert(a); if(a.size()>m) m=a.size(); } x.siz=x.siz*2+n-m; cout<<x.siz<<nl; x.dfs(x.root); } int terminator(){ L0TA; solve(); return 0; }

Compilation message (stderr)

printer.cpp: In constructor 'TrieNode::TrieNode()':
printer.cpp:25:24: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   25 |         for(int i=prt=z=0;i<26;i++)
      |                       ~^~
printer.cpp: In member function 'void Trie::insert(std::string)':
printer.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |         for(int i=0;i<a.size();i++){
      |                     ~^~~~~~~~~
printer.cpp:47:24: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   47 |             if(a.size()>x->z)
      |                ~~~~~~~~^~~~~
printer.cpp: In function 'void solve()':
printer.cpp:79:20: warning: comparison of integer expressions of different signedness: 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   79 |         if(a.size()>m)
      |            ~~~~~~~~^~
printer.cpp:73:13: warning: unused variable 'o' [-Wunused-variable]
   73 |     int n,m,o,p,q;
      |             ^
printer.cpp:73:15: warning: unused variable 'p' [-Wunused-variable]
   73 |     int n,m,o,p,q;
      |               ^
printer.cpp:73:17: warning: unused variable 'q' [-Wunused-variable]
   73 |     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...