Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define ll long long
- #include <bits/stdc++.h>
- using namespace std;
- const int OO = 1e9;
- const double EPS = 1e-9;
- class Trie {
- Trie * c[10];
- bool flag;
- public:
- Trie() {
- memset(c,0,sizeof(c));
- flag = 0;
- }
- ~Trie() {
- for(int i = 0; i < 10; i++) {
- if(c[i]) {
- delete c[i];
- }
- }
- }
- bool add(string &s, int idx = 0, bool cn = 0) {
- if(flag) {
- return false;
- }
- if(idx == s.size()) {
- flag = 1;
- return cn;
- }
- int curr = s[idx]-'0';
- if(c[curr] == 0) {
- c[curr] = new Trie();
- cn = 1;
- }
- return c[curr]->add(s,idx+1, cn);
- }
- };
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(NULL);
- cout.tie(NULL);
- int t;
- cin >> t;
- while(t--) {
- int n;
- cin >> n;
- Trie dict;
- bool con = true;
- for(int i = 0; i < n; i++) {
- string s;
- cin >> s;
- if(!dict.add(s)) {
- con = false;
- }
- }
- cout << (con ? "YES\n":"NO\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement