이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// COCI 2020/2021 Contest#3 Problem 2 - Vlak
#include <bits/stdc++.h>
using namespace std;
struct Trie {
struct Node {
Node* child[26];
bool allowNina;
bool allowEmilija;
Node() {
for (int i = 0; i < 26; ++i) {
child[i] = nullptr;
}
allowNina = false;
allowEmilija = false;
}
};
Node* root;
Trie() {
root = new Node();
}
void addString(string &s, bool 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];
if (player) {
p -> allowNina = true;
} else {
p -> allowEmilija = true;
}
}
}
};
int n, m;
Trie T;
bool isWin(Trie::Node* p, bool player) {
if (player) { // Nina
for (int c = 0; c <= 25; ++c) {
if (p -> child[c] != nullptr && p -> child[c] -> allowNina == true && !isWin(p -> child[c], false)) {
return true;
}
}
return false;
} else {
for (int c = 0; c <= 25; ++c) {
if (p -> child[c] != nullptr && p -> child[c] -> allowEmilija == true && !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, true);
}
cin >> m;
for (int i = 0; i < m; ++i) {
string s;
cin >> s;
T.addString(s, false);
}
if (isWin(T.root, true)) {
cout << "Nina";
} else {
cout << "Emilija";
}
return 0;
}
# | 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... |