Submission #768902

# Submission time Handle Problem Language Result Execution time Memory
768902 2023-06-28T20:59:08 Z DylanSmith Vlak (COCI20_vlak) C++17
70 / 70
14 ms 15132 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
 
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x),end(x)
#define lb(x,y) lower_bound(all(x),y)-begin(x)
 
mt19937 rng;

typedef struct Node {
    int adj[26], par; bool one, two;
    Node(int p = -1) {
        one = two = 0; par = p;
        fill(adj, adj + 26, -1);
    }
} node;

vector<node> tree(1);

int add(string &s) {
    int cur = 0;
    for (char c : s) {
        if (tree[cur].adj[c - 'a'] == -1) {
            tree[cur].adj[c - 'a'] = sz(tree);
            tree.emplace_back(cur);
        }
        cur = tree[cur].adj[c - 'a'];
    }
    return cur;
}

void solve() {
    int N; cin >> N;
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        int j = add(s);
        tree[j].one = true;
    }
    int M; cin >> M;
    for (int i = 0; i < M; i++) {
        string s; cin >> s;
        int j = add(s);
        tree[j].two = true;
    }
    for (int i = sz(tree) - 1; i > 0; i--) {
        tree[tree[i].par].one = tree[tree[i].par].one || tree[i].one;
        tree[tree[i].par].two = tree[tree[i].par].two || tree[i].two;
    }
    vector<int> dp1(sz(tree)), dp2(sz(tree));
    fill(all(dp1), false); fill(all(dp2), false);
    for (int i = sz(tree) - 1; i > 0; i--) {
        if (!tree[i].one) dp2[i] = true;
        if (!tree[i].two) dp1[i] = true;
        if (!dp1[i]) dp2[tree[i].par] = true;
        if (!dp2[i]) dp1[tree[i].par] = true;
    }
    cout << (dp1[0] ? "Nina" : "Emilija") << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rng = mt19937(chrono::steady_clock::now().time_since_epoch().count());
    
    solve();
 
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 580 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 576 KB Output is correct
3 Correct 1 ms 584 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 468 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 15132 KB Output is correct
2 Correct 12 ms 15028 KB Output is correct
3 Correct 11 ms 15044 KB Output is correct
4 Correct 12 ms 15040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 15044 KB Output is correct
2 Correct 11 ms 15036 KB Output is correct
3 Correct 11 ms 14952 KB Output is correct
4 Correct 14 ms 14948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 15040 KB Output is correct
2 Correct 12 ms 15040 KB Output is correct
3 Correct 11 ms 15040 KB Output is correct
4 Correct 11 ms 14960 KB Output is correct