이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int alphabet_size = 26;
int n, m;
struct trie_node
{
trie_node *children[alphabet_size];
bool contains[2];
trie_node()
{
for (int i = 0; i < alphabet_size; ++i)
{
children[i] = NULL;
}
contains[0] = false;
contains[1] = false;
}
};
trie_node *root = new trie_node;
void insert_word(trie_node *&curr, const string& s, int pos, bool which_player)
{
if (curr == NULL)
{
curr = new trie_node;
}
if (pos == s.size())
{
curr->contains[which_player] = true;
curr->contains[1 - which_player] = false;
return;
}
int child = (s[pos] - 'a');
insert_word(curr->children[child], s, pos + 1, which_player);
curr->contains[which_player] |= curr->children[child]->contains[which_player];
curr->contains[1 - which_player] |= curr->children[child]->contains[1 - which_player];
}
bool dfs(trie_node *&curr, bool which_player)
{
if (curr->contains[which_player] == false)
{
return false;
}
for (int child = 0; child < alphabet_size; ++child)
{
if (curr->children[child] != NULL && dfs(curr->children[child], 1 - which_player) == false)
{
return true;
}
}
return false;
}
void fastIO()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
int main()
{
fastIO();
cin >> n;
for (int i = 1; i <= n; ++i)
{
string s;
cin >> s;
insert_word(root, s, 0, 0);
}
cin >> m;
for (int i = 1; i <= m; ++i)
{
string s;
cin >> s;
insert_word(root, s, 0, 1);
}
if (dfs(root, 0) == true)
{
cout << "Nina" << endl;
}
else
{
cout << "Emilija" << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void insert_word(trie_node*&, const string&, int, bool)':
Main.cpp:35:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
35 | if (pos == s.size())
| ~~~~^~~~~~~~~~~| # | 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... |