Home BOJ. Phone Number List (5052)
Post
Cancel

BOJ. Phone Number List (5052)

[Link] https://www.acmicpc.net/problem/5052


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
// #include <bits/stdc++.h>
using namespace std;
#define for0(i, n) for(int i = 0; i < n; i++)
#define for1(i, n) for(int i = 1; i <= n; i++)
#define fori(s, e) for(int i = s; i < e; i++)
typedef long long ll;
const int INF = 987654321;

int n;
// vector<long> a;
vector<string> numbers;
set<string> number_set;

int main() {
  ios_base::sync_with_stdio(0);cin.tie(0); cout.tie(0);
  int t; cin >> t;
  while(t--) {
    int n; cin >> n;
    numbers.clear();
    for0(i, n) {
      string in; cin >> in;
      numbers.push_back(in);
    }
    sort(numbers.begin(), numbers.end());

    bool match_exist = false;
    for0(i, n - 1) {
      bool match = true;
      for0(j, min(numbers[i + 1].size(), numbers[i].size())) {
        if(numbers[i][j] != numbers[i+1][j]) {
           match = false;
           break;
        }
      }
      if(match) {
         match_exist = true;
        break;
      }
      if(match_exist) break;
    }
    cout << (match_exist ? "NO":"YES") << endl;
  }

  return 0;
}
This post is licensed under CC BY 4.0 by the author.