Submission #415980

# Submission time Handle Problem Language Result Execution time Memory
415980 2021-06-01T18:47:48 Z fvogel499 Vlak (COCI20_vlak) C++14
0 / 70
71 ms 55588 KB
/*
File created on 06/01/2021 at 20:08:52.
Link to problem: https://oj.uz/problem/view/COCI20_vlak
Description: create a trie and run a DP win/lose
Time complexity: O()
Space complexity: O()
Status: DEV
Copyright: Ⓒ 2021 Francois Vogel
*/

#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <queue>
#include <cstring>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>

using namespace std;

#define pb push_back
#define ins insert
#define cls clear

#define ll long long

struct Node {
    Node() {
        for (int i = 0; i < 26; i++) c[i] = nullptr;
    }
    void add(string& s, int player) {
        if (!s.empty()) {
            int i = s[s.size()-1]-'a';
            if (c[i] == nullptr) c[i] = new Node();
            p[player].pb(c[i]);
            s.pop_back();
            c[i]->add(s, player);
        }
    }
    Node* c [26];
    vector<Node*> p [2];
};

set<pair<Node*, int>> se;

// true if player wins if his turn is on node i, false otherwise
bool recDP(Node* i, int player) {
    pair<Node*, int> lp = pair<Node*, int>(i, player);
    if (se.find(lp) != se.end()) abort();
    se.ins(lp);
    for (Node* j : i->p[player]) {
        if (!recDP(j, (player == 0 ? 1 : 0))) {
            return true;
        }
    }
    return false;
}

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

    Node* root = new Node();

    int aS;
    cin >> aS;
    string lS;
    for (int i = 0; i < aS; i++) {
        cin >> lS;
        reverse(lS.begin(), lS.end());
        root->add(lS, 0);
    }
    
    int bS;
    cin >> bS;
    for (int i = 0; i < bS; i++) {
        cin >> lS;
        reverse(lS.begin(), lS.end());
        root->add(lS, 1);
    }

    bool res = recDP(root, 0);

    if (res) cout << "Nina";
    else cout << "Emilija";

    int d = 0;
    d++;
}
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 1100 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 1100 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 932 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 972 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 63 ms 53916 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 59 ms 55588 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 71 ms 52348 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -