Submission #415972

# Submission time Handle Problem Language Result Execution time Memory
415972 2021-06-01T18:43:20 Z fvogel499 Vlak (COCI20_vlak) C++14
30 / 70
1000 ms 27568 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(N)
Space complexity: O(N)
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 pii pair<int, int>
#define f first
// #define s second
 
#define pb push_back
#define ins insert
#define cls clear
 
#define ll long long
 
const int siz = 2e5;

int id = 1;
 
struct Node {
    Node(int lt) {
        t = lt;
        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(id);
                id++;
            }
            p[player].pb(c[i]);
            s.pop_back();
            c[i]->add(s, player);
        }
    }
    int t;
    Node* c [26];
    vector<Node*> p [2];
};
 
// true if player wins if his turn is on node i, false otherwise
bool recDP(Node* i, int player) {
    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(0);
 
    int aS;
    cin >> aS;
    for (int i = 0; i < aS; i++) {
        string lS;
        cin >> lS;
        reverse(lS.begin(), lS.end());
        root->add(lS, 0);
    }
    
    int bS;
    cin >> bS;
    for (int i = 0; i < bS; i++) {
        string lS;
        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 Execution timed out 1090 ms 588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 672 KB Output is correct
2 Correct 1 ms 544 KB Output is correct
3 Correct 1 ms 544 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 588 KB Output is correct
2 Correct 1 ms 588 KB Output is correct
3 Correct 16 ms 544 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 584 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 1 ms 588 KB Output is correct
4 Correct 2 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1080 ms 26820 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1074 ms 27568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1087 ms 26052 KB Time limit exceeded
2 Halted 0 ms 0 KB -