蒟蒻trie样例都过不去求助
查看原帖
蒟蒻trie样例都过不去求助
523541
Onana_in_XMFLS楼主2021/10/9 14:18

RT

#include <bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
using namespace std;
const int INF = 2147483647;
const int M = 1e5+5;
int n,m,trie[M][30],End[M],tot;
char c[M];
inline void add()
{
	int p = 1;
	for(int i = 0;i < strlen(c);++i)
	{
		int cc = c[i]-'a';
		if(!trie[p][cc]) trie[p][cc] = ++tot;
		p = trie[p][cc];
	}
	End[p] = 1;
}
inline int find()
{
	int p = 1;
	for(int i = 0;i < strlen(c);++i)
	{
		int cc = c[i]-'a';
		if(!End[p]) return 2;
		p = trie[p][cc];
	}
	if(End[p] == 1) {End[p] = 2;return 0;}
	else return 1;
}
inline LL read()
{
	LL x=0,f=1;
	char ch = getchar();
	while(!isdigit(ch)) {if(ch == '-') f = -1;ch = getchar();}
	while(isdigit(ch)) {x=x*10+ch-48;ch=getchar();}
	return f*x;
}
int main(int argc,char *argv[])
{ 
	//freopen("data.in","r",stdin);
	//freopen("data.out","w",stdout);	
	int n = read();
	while(n--) cin>>c,add();
	int m = read();
	while(m--)
	{
		cin>>c;
		if(find() == 2) puts("WRONG");
		else if(find() == 1) puts("REPEAT");
		else puts("OK");
	}
	//printf("Tide used = %.0lf.ds\n",((double)clock()/(double)CLOCKS_PER_SEC) * 1000.0);
	return 0;
}  
2021/10/9 14:18
加载中...