UKE求助
查看原帖
UKE求助
511921
ViniyenGen楼主2023/8/17 14:51
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e4 + 1;
int tr[100010][11], cnt, siz[100010];
void ins(const string& s) {
	int now = 0;
	for (auto ch : s) {
		int id = (int)(ch - '0');
		if (!tr[now][id])tr[now][id] = ++cnt;
		now = tr[now][id];
		siz[now]++;
	}
}
int query(const string& s) {
	int now = 0;
	for (auto ch : s) {
		int id = (int)(ch - '0');
		if (!tr[now][id])return 0;
		now = tr[now][id];
	}
	return siz[now];
}
int main() {
	ios::sync_with_stdio(0);
	int t, n;
	cin >> t;
	while (t--) {
		cnt = 0;
		int flag = 0;
		memset(tr, 0, sizeof(tr));
		memset(siz, 0, sizeof(siz));
		cin >> n;
		string s[100010];
		for (int i = 1; i <= n; i++) {
			cin >> s[i];
			ins(s[i]);
		}
		for (int i = 1; i <= n; i++) {
			if (query(s[i]) > 1)flag = 1;
		}
		if (flag)cout << "No\n";
		else cout << "Yes\n";
	}
	return 0;
}
2023/8/17 14:51
加载中...