Submission #198779

#TimeUsernameProblemLanguageResultExecution timeMemory
198779arnold518Type Printer (IOI08_printer)C++14
100 / 100
301 ms113388 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; typedef pair<ll, ll> pll; const int MAXN = 25000; int N; string S; vector<char> ans; struct Node { int dep, print; Node *chd[30]; Node() { int i, j; for(i=0; i<26; i++) chd[i]=NULL; } void update(string &S) { if(S.empty()) { print=1; return; } char c=S.back(); S.pop_back(); if(chd[c-'a']==NULL) chd[c-'a']=new Node(); chd[c-'a']->update(S); } void calc() { int i, j; for(i=0; i<26; i++) { if(chd[i]==NULL) continue; chd[i]->calc(); dep=max(dep, chd[i]->dep+1); } } void dfs() { int i, j; int cnt=0; vector<int> V; for(i=0; i<26; i++) { if(chd[i]==NULL) continue; V.push_back(i); } if(print) ans.push_back('P'); sort(V.begin(), V.end(), [&](const int &p, const int &q) { return chd[p]->dep<chd[q]->dep; }); for(auto i : V) { cnt++; ans.push_back(i+'a'); chd[i]->dfs(); ans.push_back('-'); } } }; Node *root=new Node(); int main() { int i, j; cin>>N; for(i=1; i<=N; i++) { cin>>S; reverse(S.begin(), S.end()); root->update(S); } root->calc(); root->dfs(); while(!ans.empty() && ans.back()=='-') ans.pop_back(); printf("%d\n", ans.size()); for(auto it : ans) printf("%c\n", it); }

Compilation message (stderr)

printer.cpp: In constructor 'Node::Node()':
printer.cpp:20:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
printer.cpp: In member function 'void Node::calc()':
printer.cpp:34:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
printer.cpp: In member function 'void Node::dfs()':
printer.cpp:45:10: warning: unused variable 'j' [-Wunused-variable]
   int i, j;
          ^
printer.cpp: In function 'int main()':
printer.cpp:81:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<char>::size_type {aka long unsigned int}' [-Wformat=]
  printf("%d\n", ans.size());
                 ~~~~~~~~~~^
printer.cpp:69:9: warning: unused variable 'j' [-Wunused-variable]
  int i, 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...