제출 #1131486

#제출 시각아이디문제언어결과실행 시간메모리
1131486NahueperaVlak (COCI20_vlak)C++20
70 / 70
20 ms22340 KiB
#include <bits/stdc++.h> using namespace std; struct TrieNodeStruct { TrieNodeStruct* children[26]; bool isEndOfWord; TrieNodeStruct() { isEndOfWord = false; for(int i = 0; i < 26; i++) { children[i] = nullptr; } } }; struct TrieStruct { TrieNodeStruct* root; TrieStruct() { root = new TrieNodeStruct(); } void insert(string word) { TrieNodeStruct* current = root; for(char c : word) { int index = c - 'a'; if(current->children[index] == nullptr) { current->children[index] = new TrieNodeStruct(); } current = current->children[index]; } current->isEndOfWord = true; } bool search(string word) { TrieNodeStruct* current = root; for(char c : word) { int index = c - 'a'; if(current->children[index] == nullptr) { return false; } current = current->children[index]; } return current->isEndOfWord; } bool startsWithDirect(string prefix) { TrieNodeStruct* current = root; for(char c : prefix) { int index = c - 'a'; if(current->children[index] == nullptr) { return false; } current = current->children[index]; } return true; // Si llegamos aquí, el prefijo existe } }; TrieStruct* game(TrieStruct n, TrieStruct m){ TrieStruct* res_t; return res_t; } bool nina(TrieNodeStruct*, TrieNodeStruct*); bool emily(TrieNodeStruct*, TrieNodeStruct*); bool nina(TrieNodeStruct* n, TrieNodeStruct* m){ bool res = false; // TrieNodeStruct* nn = n.root; for(int i = 0; i < 26 && res == false; i++){ // cout << "try: " << (char)(i + 'a') << '\n'; if(n -> children[i] == NULL){ continue; } else if(m -> children[i] == NULL){return true;} res = res || emily(n -> children[i], m -> children[i]); // cout << "nina res " << (char)(i + 'a') << " " << res << '\n'; } // cout << "nina res " << " " << res << '\n'; return res; } bool emily(TrieNodeStruct* n, TrieNodeStruct* m){ bool res = true; for(int i = 0; i < 26; i++){ if(m -> children[i] == NULL){ // cout << "emily not hace a letter " << (char)(i + 'a') << '\n'; continue;; } else if (n -> children[i] == NULL){ // cout << "nina not have a letter " << (char)(i + 'a') << '\n'; return false; } res = res && nina (n -> children[i], m -> children[i]); } return res ; } int main(){ ios::sync_with_stdio(0); cin.tie(0); TrieStruct nina_t, emily_t; int n, m; string s; cin >> n; for(int i = 0; i < n; i++){ cin >> s; nina_t.insert(s); } cin >> m; for(int i = 0; i < m; i++){ cin >> s; emily_t.insert(s); } bool res = nina(nina_t.root, emily_t.root); if(res) cout << "Nina"; else cout << "Emilija"; 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...