Submission #648456

# Submission time Handle Problem Language Result Execution time Memory
648456 2022-10-06T15:11:44 Z Elias_Obeid Type Printer (IOI08_printer) C++17
0 / 100
8 ms 5840 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 + 1> 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 2 ms 3028 KB Expected integer, but "t" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2940 KB Expected integer, but "e" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2868 KB Expected integer, but "h" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2900 KB Expected integer, but "b" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2900 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2900 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 3156 KB Expected integer, but "a" found
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 5768 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5840 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 6 ms 5840 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -