Submission #985475

# Submission time Handle Problem Language Result Execution time Memory
985475 2024-05-17T23:37:58 Z PagodePaiva Type Printer (IOI08_printer) C++17
0 / 100
53 ms 36180 KB
#include<bits/stdc++.h>

using namespace std;

int n;
int cnt;

struct Trie{
    Trie *child[26];
    int prof, tam;
    Trie(){
        prof = -1;
        tam = 0;
        for(int i = 0;i < 26;i++) child[i] = NULL;
    }
    void add(string s, int pos){
        if(pos == s.size()) return;
        if(!child[s[pos]-'a']) child[s[pos]-'a'] = new Trie();
        child[s[pos]-'a']->add(s, pos+1);
        if(prof == -1 or child[s[pos]-'a']->tam+1>child[prof]->tam){
            prof = s[pos]-'a';
            tam = child[s[pos]-'a']->tam+1;
        } 
        return;
    }
    void query(int typ){
        bool aux = true;
        for(int i = 0;i < 26;i++) if(child[i]) aux = false;
        if(aux){
            cout << 'P' << '\n';
            cnt++;
            if(cnt == n) exit(0);
            return;
        }
        if(typ == 0){
            for(int i = 0;i < 26;i++){
                if(child[i] and i != prof){
                    cout << (char)(i+'a') << '\n';
                    child[i]->query(1);
                    cout << "-\n";
                }
            }
            if(prof == -1) return;
            cout << (char)(prof+'a');
            cout << '\n';
            child[prof]->query(0);
            return;
        }
        else{
            for(int i = 0;i < 26;i++){
                if(child[i]){
                    cout << (char)(i+'a') << '\n';
                    child[i]->query(1);
                    cout << "-\n";
                }
            }
        }
    }
} trie;

int main(){
    cin >> n;
    for(int i = 0;i < n;i++){
        string s;
        cin >> s;
        trie.add(s, 0);
    }
    trie.query(0);
    return 0;
}

Compilation message

printer.cpp: In member function 'void Trie::add(std::string, int)':
printer.cpp:17:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |         if(pos == s.size()) return;
      |            ~~~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 1884 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 5980 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 20 ms 14628 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 36180 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 43 ms 28240 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -