Submission #634557

#TimeUsernameProblemLanguageResultExecution timeMemory
634557erekleVlak (COCI20_vlak)C++17
70 / 70
26 ms20396 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Node { bool word[2]{}; Node * child[26]{}; }; Node * root = new Node(); void addWord(string s, int type) { Node * cur = root; for (char c : s) { if (!cur->child[c-'a']) cur->child[c-'a'] = new Node(); cur = cur->child[c-'a']; cur->word[type] = true; } } bool winner(Node * cur, int turn = 0, string s = "") { for (int i = 0; i < 26; ++i) { string t = s; t.push_back('a'+i); if (cur->child[i] && cur->child[i]->word[turn] && winner(cur->child[i], 1-turn, t) == turn) return turn; } return 1 - turn; } int main() { int n; cin >> n; while (n--) { string s; cin >> s; addWord(s, 0); } int m; cin >> m; while (m--) { string s; cin >> s; addWord(s, 1); } cout << (winner(root) ? "Emilija" : "Nina") << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...