Submission #1087775

# Submission time Handle Problem Language Result Execution time Memory
1087775 2024-09-13T08:26:24 Z shidou26 Vlak (COCI20_vlak) C++14
70 / 70
46 ms 83216 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define all(v) v.begin(), v.end()

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;

const int N = 1e6 + 3;

struct node {
    int state;
    node *children[26];

    node () {
        state = 0;
        for(int i = 0; i < 26; i++) {
            children[i] = nullptr;
        }
    }
};

int n, m;
string a[N], b[N];

node *root = new node();

void prepare() {

}

void input() {
    cin >> n;

    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    cin >> m;

    for(int i = 1; i <= n; i++) {
        cin >> b[i];
    }
}

void insert(string s, int type) {
    node *current = root;
    for(int i = 0; i < (int)s.size(); i++) {
        int ch = s[i] - 'a';
        if(current -> children[ch] == nullptr)
            current -> children[ch] = new node();
        current = current -> children[ch];
        current -> state |= type;
    }
}

bool dfs(node *current, int turn) {
    if(!(current->state & turn)) return false;
    for(int i = 0; i < 26; i++) {
        if(current -> children[i] != nullptr && !dfs(current -> children[i], 3 - turn)) {
            return true;
        }
    }
    return false;
}

void process() {
    root -> state = 3;
    for(int i = 1; i <= n; i++) insert(a[i], 1);
    for(int i = 1; i <= m; i++) insert(b[i], 2);
    cout << (dfs(root, 1) ? "Nina" : "Emilija") << endl;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    #define task "kurumi"
    if(fopen(task".INP", "r")) {
        freopen(task".INP", "r", stdin);
        freopen(task".OUT", "w", stdout);
    }

    prepare();

    int testcase = 1; // cin >> testcase;
    for(int i = 1; i <= testcase; i++) {
        input();
        process();
    }

    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(task".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen(task".OUT", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63324 KB Output is correct
2 Correct 26 ms 63332 KB Output is correct
3 Correct 26 ms 63196 KB Output is correct
4 Correct 30 ms 63060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 63324 KB Output is correct
2 Correct 28 ms 63324 KB Output is correct
3 Correct 26 ms 63124 KB Output is correct
4 Correct 27 ms 63056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63140 KB Output is correct
2 Correct 30 ms 63068 KB Output is correct
3 Correct 28 ms 63272 KB Output is correct
4 Correct 33 ms 63060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 63056 KB Output is correct
2 Correct 25 ms 63292 KB Output is correct
3 Correct 29 ms 63064 KB Output is correct
4 Correct 26 ms 63068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 82148 KB Output is correct
2 Correct 37 ms 80904 KB Output is correct
3 Correct 46 ms 79952 KB Output is correct
4 Correct 39 ms 81748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 39 ms 82404 KB Output is correct
2 Correct 40 ms 83216 KB Output is correct
3 Correct 41 ms 81752 KB Output is correct
4 Correct 38 ms 82008 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 81408 KB Output is correct
2 Correct 37 ms 80980 KB Output is correct
3 Correct 39 ms 81488 KB Output is correct
4 Correct 43 ms 82516 KB Output is correct