답안 #986018

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
986018 2024-05-19T16:10:50 Z LOLOLO Vlak (COCI20_vlak) C++17
70 / 70
27 ms 20568 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
#define           f     first
#define           s     second
#define           pb    push_back
#define           ep    emplace
#define           eb    emplace_back
#define           lb    lower_bound
#define           ub    upper_bound
#define       all(x)    x.begin(), x.end()
#define      rall(x)    x.rbegin(), x.rend()
#define   uniquev(v)    sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define     mem(f,x)    memset(f , x , sizeof(f))
#define        sz(x)    (int)(x).size()
#define  __lcm(a, b)    (1ll * ((a) / __gcd((a), (b))) * (b))
#define          mxx    *max_element
#define          mnn    *min_element
#define    cntbit(x)    __builtin_popcountll(x)
#define       len(x)    (int)(x.length())
 
const int N = 2e5 + 10;
const int M = 1e7 + 10;

struct node {
    int prefix_count;
    bool f = 0, s = 0, df = 0, ds = 0;
    struct node *child[26];
} *head;

void init() {
    head = new node();
}

void insert(string word, int c) {
    node *current = head;
    
    for (int i = 0 ; i < (int)word.length(); ++i) {
        int letter = (int)word[i] - (int)'a';
        if (current->child[letter] == NULL)
            current->child[letter] = new node();

        current = current->child[letter];   
        if (c == 0) {
            current->f = 1;
        } else {
            current->s = 1;
        }
    }
}

void dfs(node *head) {
    head->ds = head->s;
    head->df = head->f;

    for (int i = 0; i < 26; i++) {
        if (head->child[i] != NULL) {
            dfs(head->child[i]);

            if (head->child[i]->ds) {
                head->df = 0;
            }

            if (head->child[i]->df) {
                head->ds = 0;
            }
        } 
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    init();
    head->f = head->s  = 1;

    int n;
    cin >> n;

    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        insert(s, 0);
    }

    int m;
    cin >> m;

    for (int i = 0; i < m; i++) {
        string s;
        cin >> s;
        insert(s, 1);
    }

    dfs(head);

    if (head->ds == 1) {
        cout << "Emilija\n";
    } else {
        cout << "Nina\n";
    }

    return 0;
} 
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 760 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 600 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 19292 KB Output is correct
2 Correct 19 ms 18012 KB Output is correct
3 Correct 19 ms 17028 KB Output is correct
4 Correct 18 ms 18780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 19548 KB Output is correct
2 Correct 19 ms 20568 KB Output is correct
3 Correct 16 ms 18976 KB Output is correct
4 Correct 17 ms 19216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 18656 KB Output is correct
2 Correct 17 ms 18120 KB Output is correct
3 Correct 18 ms 18524 KB Output is correct
4 Correct 27 ms 19804 KB Output is correct