社区讨论

6个WA,但是开大数组也没用

P2580于是他错误的点名开始了参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lrg46t6r
此快照首次捕获于
2024/01/16 16:51
2 年前
此快照最后确认于
2024/01/16 20:44
2 年前
查看原帖
测试点5、6、7、8、9、10都是WA,
测试点5的数据输进去卡住,猜想数组开小了
但是加大到字符串数量*字符串常度还是不行
CPP
#include <bits/stdc++.h>
using namespace std;
int ne[500005][30];
bool over1[500005];

int nee[5000005][30];
bool over2[5000005];

char s[55];

void insert()
{
	int root=0;
	int cnt=0;
	int ch;
	for(int i=0;i<strlen(s);i++)
	{
		ch=s[i]-'a';
		if(ne[root][ch]==0)
			ne[root][ch]=++cnt;
		root=ne[root][ch];
	}
	over1[root]=1;
}
void insert2()
{
	int root=0;
	int cnt=0;
	int ch;
	for(int i=0;i<strlen(s);i++)
	{
		ch=s[i]-'a';
		if(nee[root][ch]==0)
			nee[root][ch]=++cnt;
		root=nee[root][ch];
	}
	over2[root]=1;
}
bool check1()
{
	int root=0;
	int cnt=0;
	int ch;
	for(int i=0;i<strlen(s);i++)
	{
		ch=s[i]-'a';
		if(!ne[root][ch])
			return false;
		root=ne[root][ch];
	}
	return over1[root];
}
bool check2()
{
	int root=0;
	int cnt=0;
	int ch;
	for(int i=0;i<strlen(s);i++)
	{
		ch=s[i]-'a';
		if(!nee[root][ch])
			return false;
		root=nee[root][ch];
	}
	return over2[root];
}
int main()
{
	int n;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		insert();
	}
	int m;
	cin>>m;
	for(int i=0;i<m;i++)
	{
		cin>>s;
		if(check1()&&(!check2()))
		{
			cout<<"OK\n";
			insert2();
		}
		else if(check1()&&check2())
		{
			cout<<"REPEAT\n";
		}
		else
		{
			cout<<"WRONG\n";
		}
	}
	return 0;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...