답안 #803251

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
803251 2023-08-03T02:28:43 Z huantran Vlak (COCI20_vlak) C++17
10 / 70
91 ms 219624 KB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string.h>
#include <vector>

using namespace std;
typedef long long int ll;
const int maxn = 1e6;

ll n, m; // Nina = 0, Emi = 1

struct Vertex{
    ll next[26];
    ll mask = 0;
    ll output = 0;

    Vertex()
    {
        fill(begin(next), end(next), -1);
    }
};

Vertex trie[maxn];
ll cnt = 1;

void add_trie(string s, int bit)
{
    int u = 0;
    for(auto c : s)
    {
        //trie[u].mask |= (1 << bit);
        if(trie[u].next[c - 'a'] == -1)
        {
            trie[u].next[c - 'a'] = cnt++;
        }
        u = trie[u].next[c - 'a'];
        trie[u].mask |= (1 << bit);
    }
    
    trie[u].output++;
}

int dfs_trie(int u, int bit)
{
    for(int i = 0; i <= 25; i++)
    {
        int chi = trie[u].next[i];
        if(trie[u].next[i] == -1)
            continue;
        if((trie[chi].mask&(1LL << (bit^1))) && dfs_trie(chi, bit^1))
            return 0;
    }

    return 1;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    
    cin >> n;
    for(int i = 1; i <= n; i++)
    {
        string s;
        cin >> s;
        add_trie(s, 0); // Nina
    }

    cin >> m;
    for(int i = 1; i <= m; i++)
    {
        string s;
        cin >> s;
        add_trie(s, 1); // Emi
    }

    trie[0].mask |= (1 << 1);

    if(!dfs_trie(0, 0))
        cout << "Nina";
    else
        cout << "Emilija";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 219468 KB Output is correct
2 Correct 78 ms 219456 KB Output is correct
3 Incorrect 78 ms 219432 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 219468 KB Output is correct
2 Correct 77 ms 219360 KB Output is correct
3 Incorrect 77 ms 219400 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 78 ms 219476 KB Output is correct
2 Incorrect 83 ms 219448 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 219468 KB Output is correct
2 Correct 77 ms 219408 KB Output is correct
3 Correct 77 ms 219404 KB Output is correct
4 Correct 76 ms 219440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 219608 KB Output is correct
2 Incorrect 82 ms 219624 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 219560 KB Output is correct
2 Incorrect 82 ms 219588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 82 ms 219608 KB Output is correct
2 Incorrect 82 ms 219620 KB Output isn't correct
3 Halted 0 ms 0 KB -