# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
839488 | Lilinta | Vlak (COCI20_vlak) | C++14 | 13 ms | 20436 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// COCI 2020/2021 Contest#3 Problem 2 - Vlak
#include <bits/stdc++.h>
using namespace std;
struct Trie {
struct Node {
Node* child[26];
int allow;
Node() {
for (int i = 0; i < 26; ++i) {
child[i] = nullptr;
}
allow = 0;
}
};
Node* root;
Trie() {
root = new Node();
}
void addString(string &s, int player) {
Node* p = root;
for (char f : s) {
int c = f - 'a';
if (p -> child[c] == nullptr) {
p -> child[c] = new Node();
}
p = p -> child[c];
p -> allow += player;
}
}
};
int n, m;
Trie T;
bool isWin(Trie::Node* p, bool player) {
if (player) { // Nina
for (char c = 0; c <= 25; ++c) {
if (p -> child[c] != nullptr && p -> child[c] -> allow != 2 && !isWin(p -> child[c], false)) {
return true;
}
}
return false;
} else {
for (char c = 0; c <= 25; ++c) {
if (p -> child[c] != nullptr && p -> child[c] -> allow != 1 && !isWin(p -> child[c], true)) {
return true;
}
}
return false;
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
for (int i = 0; i < n; ++i) {
string s;
cin >> s;
T.addString(s, 1);
}
cin >> m;
for (int i = 0; i < m; ++i) {
string s;
cin >> s;
T.addString(s, 2);
}
if (isWin(T.root, true)) {
cout << "Nina";
} else {
cout << "Emilija";
}
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |