# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
475749 |
2021-09-24T00:21:22 Z |
KhaledFarhat |
Vlak (COCI20_vlak) |
C++14 |
|
21 ms |
15356 KB |
#include <bits/stdc++.h>
using namespace std;
struct TrieNode {
TrieNode() {
canWin[0] = canWin[1] = -1;
hasColor[0] = hasColor[1] = false;
memset(child, 0, sizeof child);
}
int canWin[2];
bool hasColor[2];
int child[26];
};
struct Trie {
Trie() {
fetchNode();
root = fetchNode();
}
void insertWord(const string& s, int color) {
int current = root;
for (int i = 0; i < (int)s.size(); ++i) {
int edge = s[i] - 'a';
if (nodes[current].child[edge] == 0) {
int index = fetchNode();
nodes[current].child[edge] = index;
}
current = nodes[current].child[edge];
nodes[current].hasColor[color] = true;
}
}
int canWin(int node, int turn) {
int& ret = nodes[node].canWin[turn];
if (ret != -1) {
return ret;
}
for (int edge = 0; edge < 26; ++edge) {
int child = nodes[node].child[edge];
if (child != 0 && nodes[child].hasColor[turn] == true && canWin(child, turn ^ 1) == false) {
return ret = 1;
}
}
return ret = 0;
}
int fetchNode() {
nodes.push_back(TrieNode());
return (int)nodes.size() - 1;
}
int root;
vector<TrieNode> nodes;
};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
Trie trie;
int n;
cin >> n;
while (n--) {
string s;
cin >> s;
trie.insertWord(s, 0);
}
int m;
cin >> m;
while (m--) {
string s;
cin >> s;
trie.insertWord(s, 1);
}
cout << (trie.canWin(1, 0) == 1 ? "Nina" : "Emilija");
return 0;
}
# |
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 |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 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 |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
1 ms |
588 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
460 KB |
Output is correct |
2 |
Correct |
1 ms |
588 KB |
Output is correct |
3 |
Correct |
1 ms |
588 KB |
Output is correct |
4 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
15292 KB |
Output is correct |
2 |
Correct |
16 ms |
15264 KB |
Output is correct |
3 |
Correct |
16 ms |
15308 KB |
Output is correct |
4 |
Correct |
16 ms |
15288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15356 KB |
Output is correct |
2 |
Correct |
15 ms |
15352 KB |
Output is correct |
3 |
Correct |
15 ms |
15248 KB |
Output is correct |
4 |
Correct |
16 ms |
15348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
15292 KB |
Output is correct |
2 |
Correct |
19 ms |
15272 KB |
Output is correct |
3 |
Correct |
15 ms |
15252 KB |
Output is correct |
4 |
Correct |
17 ms |
15292 KB |
Output is correct |