답안 #531318

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531318 2022-02-28T11:52:05 Z speedyArda Vlak (COCI20_vlak) C++14
0 / 70
31 ms 19964 KB
#include "bits/stdc++.h"

using namespace std;

const int MAXN = 2e5;

struct trie_node 
{
    int next_node[26];
    bool leaf;
    vector<char> owner;
    trie_node() 
    {
        fill(next_node, next_node + 26, -1);
    }
};
/*trie_node trie_nina[MAXN + 5];

trie_node trie_emilija[MAXN + 5];
*/

vector<trie_node> trie;



void add_string_nina(string input) 
{
    int v = 0;
    for(char ch : input) 
    {
        int c = ch - 'a';
        if(trie[v].next_node[c] == -1)
        {
            trie[v].next_node[c] = trie.size();
            trie.emplace_back();
        } 
        v = trie[v].next_node[c];
        if(trie[v].owner.size() == 0 || (trie[v].owner.size() == 1 && trie[v].owner[0] == 'E'))
        trie[v].owner.push_back('N');
    }

    trie[v].leaf = true;
}

void add_string_emilija(string input) 
{
    int v = 0;
    for(char ch : input) 
    {
        int c = ch - 'a';
        if(trie[v].next_node[c] == -1)
        {
            trie[v].next_node[c] = trie.size();
            trie.emplace_back();
        } 
        v = trie[v].next_node[c];
        if(trie[v].owner.size() == 0 || (trie[v].owner.size() == 1 && trie[v].owner[0] == 'N'))
        trie[v].owner.push_back('E');
    }

    trie[v].leaf = true;
}

bool dfs_nina(int v, int depth) 
{
    bool valid = false;
    bool children = false;
    for(int i = 0; i < 26; i++) 
    {
        if(trie[v].next_node[i] == -1)
            continue;
        children = true;
        if(trie[trie[v].next_node[i]].owner.size() == 1 && trie[trie[v].next_node[i]].owner[0] == 'N' && depth % 2 == 0) {
            return true;
        }
        else if((trie[trie[v].next_node[i]].owner.size() == 1 && trie[trie[v].next_node[i]].owner[0] == 'E' && depth % 2 == 1))
        {    return false; 
        }
        else 
        {
            if(trie[trie[v].next_node[i]].owner.size() == 2) {
                bool temp =  dfs_nina(trie[v].next_node[i], depth + 1);
                if(temp)
                    valid = true;
            }
        }
    }
    if(!children && depth % 2 == 1)
        valid = true;
    return valid;
}

int main() 
{
    trie_node root = trie_node();
    trie.push_back(root);
    int n, m;
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        string input;
        cin >> input;
        add_string_nina(input);
    }

    cin >> m;
    for(int i = 1; i <= m; i++)
    {
        string input;
        cin >> input;
        add_string_emilija(input);
    }

    if(dfs_nina(0, 0))
        cout << "Nina\n";
    else
        cout << "Emilija\n";
    
    
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 664 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 680 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Incorrect 1 ms 680 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 716 KB Output is correct
3 Incorrect 1 ms 460 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 460 KB Output is correct
2 Correct 1 ms 628 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Incorrect 1 ms 548 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 19964 KB Output is correct
2 Incorrect 30 ms 19880 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 25 ms 19940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 19924 KB Output isn't correct
2 Halted 0 ms 0 KB -