#include<bits/stdc++.h> // Recursive version using pointers // Using C++14(GCC9) // 576ms/63.32MB without O2 // 478ms/63.35MB with O2 namespace Pozhu{ usingnamespace std; #define N 10010 #define M 100010
#include<bits/stdc++.h> // Non-recursive version using pointers // Using C++14(GCC9) // 564ms/63.34MB without O2 // 449ms/63.29MB with O2 namespace Pozhu{ usingnamespace std; #define N 10010 #define M 100010
structTrie { Trie* son[26]; char val; int cnt; bool iskey; int be_find; Trie() : val(0),cnt(0),iskey(false),be_find(false) {for(int i = 0;i < 26;i++) son[i] = nullptr;} Trie(char _v) : val(_v),cnt(1),iskey(false),be_find(false) {for(int i = 0;i < 26;i++) son[i] = nullptr;} }rt;
intfind(char* s) { int len = strlen(s),pos = 0; Trie* now = &rt; while(pos < len) { if(now -> son[s[pos] - 'a'] == nullptr) return0; now = now -> son[s[pos] - 'a']; pos++; } if(now -> iskey) return ++now -> be_find; elsereturn0; }
voidadd(char* s) { int len = strlen(s),pos = 0; Trie* now = &rt; while(pos < len) { if(now -> son[s[pos] - 'a'] == nullptr) now -> son[s[pos] - 'a'] = newTrie(s[pos]); else now -> son[s[pos] - 'a'] -> cnt++; now = now -> son[s[pos] - 'a']; pos++; } return now -> iskey = true,void(); }
int n,m; char s[60];
voidmain() { scanf("%d",&n); for(int i = 1;i <= n;i++) { scanf("%s",s); add(s); } scanf("%d",&m); for(int i = 1;i <= m;i++) { scanf("%s",s); int x = find(s); if(!x) puts("WRONG"); elseif(x == 1) puts("OK"); elseputs("REPEAT"); } return; }
#include<bits/stdc++.h> // Recursive version using arrays // Using C++14(GCC9) // 518ms/57.81MB without O2 // 466ms/57.79MB with O2 namespace Pozhu{ usingnamespace std; #define N 10010 #define M 100010
#include<bits/stdc++.h> // Non-recursive version using arrays // Using C++14(GCC9) // 476ms/57.81MB without O2 // 463ms/57.81MB with O2 namespace Pozhu{ usingnamespace std; #define N 10010 #define M 100010