Submission #1113210

# Submission time Handle Problem Language Result Execution time Memory
1113210 2024-11-16T03:51:25 Z Nahuepera Type Printer (IOI08_printer) C++14
0 / 100
13 ms 6228 KB
#include <bits/stdc++.h>
#define tip tuple<int, string>

using namespace std;

struct TrieNodeStruct {
    TrieNodeStruct* children[26];
    bool isEndOfWord;
    
    TrieNodeStruct() {
        isEndOfWord = false;
        for(int i = 0; i < 26; i++) {
            children[i] = nullptr;
        }
    }
};

struct TrieStruct {
    TrieNodeStruct* root;
    
    TrieStruct() {
        root = new TrieNodeStruct();
    }
    
    string insert(string word) {  
      TrieNodeStruct* current = root;
      string res = "";
      
      for(char c : word) {
        int index = c - 'a';
        if(current->children[index] == nullptr) {
          current->children[index] = new TrieNodeStruct();
        }
        else{
          res += c;
        }
        current = current->children[index];
      }
      current->isEndOfWord = true;

      return res;
    }
    
    bool search(string word) {
        TrieNodeStruct* current = root;
        for(char c : word) {
            int index = c - 'a';
            if(current->children[index] == nullptr) {
                return false;
            }
            current = current->children[index];
        }
        return current->isEndOfWord;
    }

    bool startsWithDirect(string prefix) {
        TrieNodeStruct* current = root;
        for(char c : prefix) {
            int index = c - 'a';
            if(current->children[index] == nullptr) {
                return false;
            }
            current = current->children[index];
        }
        return true;  // Si llegamos aquí, el prefijo existe
    }
};

int main(){
  int n; cin >> n;
  vector<tip> lst(n);
  for(int i = 0; i < n; i++){
    string s; cin >> s;
    lst[i] = make_tuple(s.length(), s);
  }

  sort(lst.begin(), lst.end());

  TrieStruct t;
  string res = "";
  auto [nl, sl] = lst[0];
  string r = t.insert(sl);
  int last = n;
  for(int j = 0; j < n; j++){
    res += sl[j];
    res += '\n';
  }

  // res += ('P' + '\n');
  

  for(int i = 1; i < n; i++){
    auto [n, s] = lst[i];
    string r = t.insert(s);
    // cout << s << ": " << r << '\n';
    for(int j = 0; j < last - r.length(); j++){
      res += '-';
      res += '\n';
    }
    for(int j = 0 + r.length(); j < n; j++){
      res += s[j];
      res += '\n';
    }
    res += 'P';
    res += '\n';

    last = n;
    // if(i == 0) continue;
  }
  cout << res << '\n';

}

Compilation message

printer.cpp: In function 'int main()':
printer.cpp:81:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   81 |   auto [nl, sl] = lst[0];
      |        ^
printer.cpp:93:10: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   93 |     auto [n, s] = lst[i];
      |          ^
printer.cpp:96:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   96 |     for(int j = 0; j < last - r.length(); j++){
      |                    ~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "n" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 592 KB Expected integer, but "p" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 336 KB Expected integer, but "x" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 1984 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 6228 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 1360 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 11 ms 2528 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 13 ms 2748 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -