Submission #648457

# Submission time Handle Problem Language Result Execution time Memory
648457 2022-10-06T15:13:00 Z Elias_Obeid Type Printer (IOI08_printer) C++17
0 / 100
75 ms 70212 KB
#include <bits/stdc++.h>
using namespace std;

const int LEN = 25'000;
const int ALPHABET = 26;

struct TrieNode
{
    bool is_leaf;
    array<int, ALPHABET> next_nodes;
    TrieNode()
    {
        is_leaf = false;
        next_nodes.fill(-1);
    }
};

int current_trie_node = 0;
array<TrieNode, LEN * ALPHABET> trie;

int fetchNode()
{
    trie[current_trie_node] = TrieNode();
    return current_trie_node++;
}

const int ROOT = fetchNode();

void addWord(const string &word)
{
    int current_node = 0;
    for (int i = 0; i < (int)word.size(); ++i)
    {
        int letter = (word[i] - 'a');
        if (trie[current_node].next_nodes[letter] == -1)
        {
            trie[current_node].next_nodes[letter] = fetchNode();
        }
        current_node = trie[current_node].next_nodes[letter];
    }
    trie[current_node].is_leaf = true;
}

vector<char> answer;

void depthFirstSearch(int node)
{
    if (trie[node].is_leaf)
    {
        answer.emplace_back('P');
    }

    for (int letter = 0; letter < ALPHABET; ++letter)
    {
        if (trie[node].next_nodes[letter] != -1)
        {
            answer.emplace_back(char(letter + 'a'));
            depthFirstSearch(trie[node].next_nodes[letter]);
            answer.emplace_back('-');
        }
    }
}

int main()
{
    int N;
    cin >> N;

    for (int i = 0; i < N; ++i)
    {
        string S;
        cin >> S;
        addWord(S);
    }
    depthFirstSearch(ROOT);

    while (!answer.empty() && answer.back() == '-')
    {
        answer.pop_back();
    }

    for (char letter : answer)
    {
        cout << letter << "\n";
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 31 ms 68936 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 68988 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 28 ms 68972 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 68916 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 68940 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 69008 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 39 ms 69116 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 45 ms 69448 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 70212 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 71 ms 70004 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -