欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Phone List

程序员文章站 2022-06-02 19:47:37
...

Phone List
Phone List

#include <bits/stdc++.h>
using namespace std;

const int SIZE = 1e5 + 10;
int trie[SIZE][10], sign[SIZE], tot = 1;
char ss[SIZE][20];

void insert(char* str) {
	int len = strlen(str), p = 1;
	for (int i = 0; i < len; ++i) {
		int ch = str[i] - '0';
		if (!trie[p][ch]) trie[p][ch] = ++tot;
		p = trie[p][ch];
	}
	sign[p]++;
}

bool search(char* str) {
	int len = strlen(str), p = 1;
	for(int i = 0; i < len; ++i) {
		int ch = str[i] - '0';
		if (sign[p]) return true;
		p = trie[p][ch];
	}
	return false;
}

bool solve(int n) {
	for (int i = 1; i <= n; ++i) insert(ss[i]);
	for (int i = 1; i <= n; ++i) {
		if (search(ss[i])) return true;
	}
	return false;
}

int main() {
	int T; cin >> T;
	while (T--) {
		int n; cin >> n;
		for (int i = 1; i <= n; ++i) scanf("%s",ss[i]);
		if (solve(n)) puts("NO");
		else  puts("YES");
		memset(trie,0,sizeof(trie));
		memset(sign,false,sizeof(sign));
		tot = 1;
	}
	return 0;
}
相关标签: ACM-ICPC题集