Submission #881015

# Submission time Handle Problem Language Result Execution time Memory
881015 2023-11-30T10:51:30 Z TAhmed33 Vlak (COCI20_vlak) C++
70 / 70
16 ms 43096 KB
#include <bits/stdc++.h>
using namespace std;
int a[200001][26];
int b[200001][26];
int sze1 = 0, sze2 = 0;
void insert1 (string s) {
    int cur = 0;
    for (auto i : s) {
        if (a[cur][i - 'a'] == -1) a[cur][i - 'a'] = ++sze1;
        cur = a[cur][i - 'a'];
    }
}
void insert2 (string s) {
    int cur = 0;
    for (auto i : s) {
        if (b[cur][i - 'a'] == -1) b[cur][i - 'a'] = ++sze2;
        cur = b[cur][i - 'a'];
    }
}
int dp[200001][2];
int ans (int x, int y, int c) {
    int &ret = dp[x][c];
    if (ret != -1) return ret;
    ret = 0;
    if (!c) {
        for (int i = 0; i < 26; i++) {
            if (a[x][i] != -1 && b[y][i] == -1) {
                ret = 1;
            } else if (a[x][i] != -1) {
                ret |= !ans(a[x][i], b[y][i], 1);
            }
        }
    } else {
        for (int i = 0; i < 26; i++) {
            if (b[y][i] != -1 && a[x][i] == -1) {
                ret = 1;
            } else if (b[y][i] != -1) {
                ret |= !ans(a[x][i], b[y][i], 0);
            }
        }
    }
    return ret;
}
int main () {
    memset(a, -1, sizeof(a));
    memset(b, -1, sizeof(b));
    memset(dp, -1, sizeof(dp));
    int n;
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        insert1(s);
    }
    cin >> n;
    while (n--) {
        string s;
        cin >> s;
        insert2(s);
    }
    cout << (ans(0, 0, 0) ? "Nina" : "Emilija") << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 42584 KB Output is correct
2 Correct 6 ms 42584 KB Output is correct
3 Correct 6 ms 42512 KB Output is correct
4 Correct 6 ms 42588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 42588 KB Output is correct
2 Correct 6 ms 42588 KB Output is correct
3 Correct 6 ms 42584 KB Output is correct
4 Correct 7 ms 42588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 42584 KB Output is correct
2 Correct 6 ms 42584 KB Output is correct
3 Correct 7 ms 42584 KB Output is correct
4 Correct 6 ms 42588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 42588 KB Output is correct
2 Correct 7 ms 42588 KB Output is correct
3 Correct 7 ms 42588 KB Output is correct
4 Correct 6 ms 42588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 42584 KB Output is correct
2 Correct 12 ms 42584 KB Output is correct
3 Correct 12 ms 42844 KB Output is correct
4 Correct 12 ms 43096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 42588 KB Output is correct
2 Correct 11 ms 42696 KB Output is correct
3 Correct 11 ms 42844 KB Output is correct
4 Correct 12 ms 42840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 42588 KB Output is correct
2 Correct 12 ms 42840 KB Output is correct
3 Correct 14 ms 42844 KB Output is correct
4 Correct 12 ms 42844 KB Output is correct