이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |