/*
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 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;
set<pii> m;
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) {
if (m.find(pii(i->t, player)) != m.end()) abort();
m.ins(pii(i->t, 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++;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
1100 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
1100 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
972 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
932 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
67 ms |
54088 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
62 ms |
55620 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
61 ms |
52508 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |