Problem p02701 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <memory>
#include <set>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double l_double;

#define vtr vector
#define PB push_back
#define EB emplace_back
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define st_ct static_cast // <>
#define TEST                                                                   \\
  uint _{};                                                                    \\
  cin >> _;                                                                    \\
  while (_--)
#define PI (3.1415926535897932384626433832795)
#define MOD st_ct<int>(1e9 + 7)
#define EPS 1e-9
#define deb1(x) cerr << #x << " -> " << x << endl;
#define deb2(x, y)                                                             \\
  cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ")" << endl;
#define deb3(x, y, z)                                                          \\
  cerr << "(" << #x << ", " << #y << ", " << #z << ") -> (" << x << ", " << y  \\
       << ", " << z << ")" << endl;
#define debVV(V) cerr << #V << ":\\n" << V << endl; // 2D

// 1D
template <typename T> istream &operator>>(istream &is, vector<T> &A) {
  for (T &v : A)
    is >> v;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
  for (T const &v : A)
    os << v << " ";
  return os;
}

template <typename T> void vtrV(const vector<T> &A) {
  for (T const &val : A)
    cout << val << endl;
}

// 2D
template <typename T> istream &operator>>(istream &is, vector<vector<T>> &A) {
  for (vector<T> &i : A)
    for (T &j : i)
      is >> j;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &A) {
  for (vector<T> const &i : A) {
    for (T const &j : i)
      os << j << " ";
    os << endl;
  }
  return os;
}

template <typename T> void vvtrNS(const vector<vector<T>> &A) {
  for (vector<T> const &i : A) {
    for (T const &j : i)
      cout << j;
    cout << endl;
  }
}

template <typename T> T cntDigits(const T &N) { return (floor(log10(N)) + 1); }

template <typename T> bool isPowOfTwo(const T &N) {
  return (N && (!(N & (N - 1))));
}

template <typename T> T lcm(T a, T b) { return ((a * b) / gcd(a, b)); }
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout.setf(std::ios::boolalpha);
  cout << std::fixed;
  cout << std::setprecision(6); // default
  /* -------------------------------- */

  int n{};
  cin >> n;
  set<string> arr{};
  while (n--) {
    string s{};
    cin >> s;
    arr.insert(s);
  }
  cout << arr.size() << endl;
  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned uint;
typedef long double l_double;

#define vtr vector
#define PB push_back
#define EB emplace_back
#define gcd __gcd
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define st_ct static_cast // <>
#define TEST                                                                   \\
  uint _{};                                                                    \\
  cin >> _;                                                                    \\
  while (_--)
#define PI (3.1415926535897932384626433832795)
#define MOD st_ct<int>(1e9 + 7)
#define EPS 1e-9
#define deb1(x) cerr << #x << " -> " << x << endl;
#define deb2(x, y)                                                             \\
  cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ")" << endl;
#define deb3(x, y, z)                                                          \\
  cerr << "(" << #x << ", " << #y << ", " << #z << ") -> (" << x << ", " << y  \\
       << ", " << z << ")" << endl;
#define debVV(V) cerr << #V << ":\\n" << V << endl; // 2D

// 1D
template <typename T> istream &operator>>(istream &is, vector<T> &A) {
  for (T &v : A)
    is >> v;
  return is;
}

template <typename T> ostream &operator<<(ostream &os, const vector<T> &A) {
  for (T const &v : A)
    os << v << " ";
  return os;
}

template <typename T> void vtrV(const vector<T> &A) {
  for (T const &val : A)
    cout << val << endl;
}

// 2D
template <typename T> istream &operator>>(istream &is, vector<vector<T>> &A) {
  for (vector<T> &i : A)
    for (T &j : i)
      is >> j;
  return is;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<vector<T>> &A) {
  for (vector<T> const &i : A) {
    for (T const &j : i)
      os << j << " ";
    os << endl;
  }
  return os;
}

template <typename T> void vvtrNS(const vector<vector<T>> &A) {
  for (vector<T> const &i : A) {
    for (T const &j : i)
      cout << j;
    cout << endl;
  }
}

template <typename T> T cntDigits(const T &N) { return (floor(log10(N)) + 1); }

template <typename T> bool isPowOfTwo(const T &N) {
  return (N && (!(N & (N - 1))));
}

template <typename T> T lcm(T a, T b) { return ((a * b) / gcd(a, b)); }
/* -------------------------------------------------------- */
/* -------------------------------------------------------- */

bool inSet(const vtr<string> &set, const string &s) {
  for (auto const &val : set)
    if (val == s)
      return true;
  return false;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  // cout.setf(std::ios::boolalpha);
  cout << std::fixed;
  cout << std::setprecision(6); // default
  /* -------------------------------- */

  int n{};
  cin >> n;
  vtr<string> set{};
  while (n--) {
    string s{};
    cin >> s;
    if (!inSet(set, s))
      set.EB(s);
  }
  cout << set.size() << endl;
  return 0;
}