Submission #321261

# Submission time Handle Problem Language Result Execution time Memory
321261 2020-11-11T18:30:03 Z vukasinbabic06 Type Printer (IOI08_printer) C++14
100 / 100
169 ms 98788 KB
#include <bits/stdc++.h>
 
using namespace std;
int ans = 0;
struct Node{
  int last;
  int is;
  Node *next[26];
  Node(){
    last = false;
    is = false;
    for(int i = 0; i < 26; i++) next[i] = NULL;
  }
} *root = new Node;
void insert(Node *root, string s){
  for(int i = 0; i < s.size(); i++){
      int index = s[i] - 'a';
      if(root -> next[index] == NULL) {
        root -> next[index] = new Node;
        ans ++;
      }
      root = root -> next[index];
  }
  root -> last = 1;
}
void search(Node *root, string s){
    for(int i = 0; i < s.size(); i++){
      int index = s[i] - 'a';
      root = root -> next[index];
      root -> is = 1;
    }
    root -> last = 1;
}
void Print(Node *root){
    for(int i = 0; i < 26; i++){
      if(root -> next[i] != NULL && !root -> next[i] -> is){
            cout << char(i + 'a')<< '\n';
            if(root -> next[i] -> last) cout << "P" << '\n';
            Print(root -> next[i]);  cout << "-" << '\n';
      }
    }
}
int n;
string st;
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  for(int i = 1; i <= n; i++) {
      string s;
      cin >> s;
      insert(root, s);
      if(s.size() > st.size()) st = s;
  }
  search(root, st);
  cout << ans * 2 + n - st.size() << '\n';
  Print(root);
  for(int i = 0; i < st.size(); i++){
      cout << st[i] << '\n';
      Print(root -> next[st[i] - 'a']);
      if(root -> next[st[i] - 'a'] -> last) cout << "P" << '\n';
      root = root -> next[st[i] - 'a'];
  }
}

Compilation message

printer.cpp: In function 'void insert(Node*, std::string)':
printer.cpp:16:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for(int i = 0; i < s.size(); i++){
      |                  ~~^~~~~~~~~~
printer.cpp: In function 'void search(Node*, std::string)':
printer.cpp:27:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |     for(int i = 0; i < s.size(); i++){
      |                    ~~^~~~~~~~~~
printer.cpp: In function 'int main()':
printer.cpp:59:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |   for(int i = 0; i < st.size(); i++){
      |                  ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 2 ms 1132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1772 KB Output is correct
2 Correct 4 ms 2284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 5868 KB Output is correct
2 Correct 21 ms 12396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 14444 KB Output is correct
2 Correct 10 ms 3308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 62 ms 36068 KB Output is correct
2 Correct 136 ms 82916 KB Output is correct
3 Correct 75 ms 42724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 54 ms 28132 KB Output is correct
2 Correct 169 ms 98788 KB Output is correct
3 Correct 85 ms 48484 KB Output is correct
4 Correct 145 ms 93156 KB Output is correct