Submission #531319

#TimeUsernameProblemLanguageResultExecution timeMemory
531319fcwVlak (COCI20_vlak)C++17
70 / 70
19 ms21928 KiB
#include <bits/stdc++.h> #define st first #define nd second using lint = int64_t; constexpr int mod = int(1e9) + 7; constexpr int inf = 0x3f3f3f3f; constexpr int ninf = 0xcfcfcfcf; constexpr lint linf = 0x3f3f3f3f3f3f3f3f; const long double pi = acosl(-1.0); // Returns -1 if a < b, 0 if a = b and 1 if a > b. int cmp_double(double a, double b = 0, double eps = 1e-9) { return a + eps > b ? b + eps > a ? 0 : 1 : -1; } using namespace std; int trie[200100][26]; int flag[200100]; bool w[200100]; int main() { cin.tie(nullptr)->sync_with_stdio(false); memset(trie, -1, sizeof trie); int n, m; cin>>n; vector<string>a(n); int sz = 1; for(int i=0;i<n;i++){ cin>>a[i]; int cur = 0; for(char c : a[i]){ if(trie[cur][c-'a'] == -1){ trie[cur][c-'a'] = sz++; } cur = trie[cur][c-'a']; flag[cur] |= 1; } } cin>>m; vector<string>b(m); for(int i=0;i<m;i++){ cin>>b[i]; int cur = 0; for(char c : b[i]){ if(trie[cur][c-'a'] == -1){ trie[cur][c-'a'] = sz++; } cur = trie[cur][c-'a']; flag[cur] |= 2; } } auto dfs = [&](auto& self, int cur, int num) -> bool{ bool ok = 0; for(int i=0;i<26;i++){ if(trie[cur][i] == -1) continue; if(num&1){ if(flag[trie[cur][i]] == 2) ok = 1; else if(flag[trie[cur][i]] == 3) ok |= !self(self, trie[cur][i], num+1); } else{ if(flag[trie[cur][i]] == 1) ok = 1; else if(flag[trie[cur][i]] == 3) ok |= !self(self, trie[cur][i], num+1); } } return w[cur] = ok; }; dfs(dfs, 0, 0); if(w[0]) cout<<"Nina\n"; else cout<<"Emilija\n"; return 0; } /* [ ]Leu o problema certo??? [ ]Ver se precisa de long long [ ]Viu o limite dos fors (é n? é m?) [ ]Tamanho do vetor, será que é 2e5 em vez de 1e5?? [ ]Testar sample [ ]Testar casos de borda [ ]1LL no 1LL << i [ ]Testar mod (é 1e9+7, mesmo?, será que o mod não ficou negativo?) */
#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...