字典树10分求条
查看原帖
字典树10分求条
530468
_determination_楼主2023/11/14 10:47

RT,将鼠标放上测试点发现将OK输出为WRONG(wrong answer On line 1 column 1, read W, expected O.)

求条

#include<bits/stdc++.h>
#define int long long
using namespace std;
int t[500010][30],tot;
bool name[500010],rep[500010];
void insert(string s)
{
	int node=0;
	for ( int i = 0 ; i < s.size() ; i++ )
	{
		if(!t[node][s[i]-'a'])
		{
			t[node][s[i]-'a']=++tot;
		}
		node=t[node][s[i]-'a'];
	}
	name[node]=1;
}
void calc(string s)
{
	int node=0;
	for ( int i = 0 ; i < s.size() ; i++ )
	{
		if(!t[node][s[i]-'a'])
		{
			cout << "WRONG" << endl;
			return;
		}
	}
	if(!name[node])
	{
		cout << "WRONG" << endl;
		return;
	}
	if(!rep[node])
	{
		cout << "OK" << endl;
		rep[node]=1;
	}else{
		cout << "REPEAT" << endl;
	}
}
signed main(){
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for ( int i = 1 ; i <= n ; i++ )
	{
		string s;
		cin >> s;
		insert(s);
	}
	int q;
	cin >> q;
	while(q--)
	{
		string s;
		cin >> s;
		calc(s);
	}
	return 0;
}

link:here

2023/11/14 10:47
加载中...