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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <char cmp = '<'> bool icmp(ll a, ll b) {
  if (cmp == '>')
    return a > b;
  else
    return a < b;
}
namespace enhanced_pair {
typedef pair<ll, ll> pll;
ostream &operator<<(ostream &o, const pll a) {
  o << a.first << " " << a.second;
  return o;
}
istream &operator>>(istream &i, pll &p) {
  i >> p.first >> p.second;
  return i;
}
template <char cmp1 = '<', char cmp2 = '<'> bool pcmp(pll a, pll b) {
  return icmp<cmp1>(a.first, b.first) ||
         (a.first == b.first && icmp<cmp2>(a.second, b.second));
}
template <char cmp1 = '<', char cmp2 = '<'> struct pcmpobj {
  bool operator()(pll a, pll b) { return pcmp<cmp1, cmp2>(a, b); }
};
} // namespace enhanced_pair
using namespace enhanced_pair;
const ll BIG = 1e18;
const ll NMAX = 2e5 + 5;
const ll MOD = 1e9 + 7;
pll v[NMAX];
pll tofraction(string x) {
  ll n = 0, p2 = 0, p5 = 0, p10 = 0;
  bool point = 0;
  for (ll i = 0; i < x.size(); i++)
    if (x[i] != '.')
      n = n * 10 + x[i] - '0';
  for (ll i = 0; i < x.size(); i++) {
    if (point == 1)
      p10++;
    if (x[i] == '.')
      point = 1;
  }
  while (n && n % 2 == 0) {
    n /= 2;
    p2++;
  }
  while (n && n % 5 == 0) {
    n /= 5;
    p5++;
  }
  return {p2 - p10, p5 - p10};
}
ll cntatleast[55][55];
void tc() {
  ll n, ans = 0;
  string x;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> x;
    v[i] = tofraction(x);
    for (ll n1 = -25; n1 <= v[i].first; n1++)
      for (ll n2 = -25; n2 <= v[i].second; n2++)
        cntatleast[n1 + 25][n2 + 25]++;
  }
  for (ll i = 0; i < n; i++) {
    ans += cntatleast[-v[i].first + 25][-v[i].second + 25] -
           (v[i].first >= 0 && v[i].second >= 0);
  }
  cout << ans / 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // ll q; cin>>q; while(q--)
  tc();

  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template <char cmp = '<'> bool icmp(ll a, ll b) {
  if (cmp == '>')
    return a > b;
  else
    return a < b;
}
namespace enhanced_pair {
typedef pair<ll, ll> pll;
ostream &operator<<(ostream &o, const pll a) {
  o << a.first << " " << a.second;
  return o;
}
istream &operator>>(istream &i, pll &p) {
  i >> p.first >> p.second;
  return i;
}
template <char cmp1 = '<', char cmp2 = '<'> bool pcmp(pll a, pll b) {
  return icmp<cmp1>(a.first, b.first) ||
         (a.first == b.first && icmp<cmp2>(a.second, b.second));
}
template <char cmp1 = '<', char cmp2 = '<'> struct pcmpobj {
  bool operator()(pll a, pll b) { return pcmp<cmp1, cmp2>(a, b); }
};
} // namespace enhanced_pair
using namespace enhanced_pair;
const ll BIG = 1e18;
const ll NMAX = 2e5 + 5;
const ll MOD = 1e9 + 7;
pll v[NMAX];
pll tofraction(string x) {
  ll n = 0, p2 = 0, p5 = 0, p10 = 0;
  bool point = 0;
  for (ll i = 0; i < x.size(); i++)
    if (x[i] != '.')
      n = n * 10 + x[i] - '0';
  for (ll i = 0; i < x.size(); i++) {
    if (point == 1)
      p10++;
    if (x[i] == '.')
      point = 1;
  }
  while (n && n % 2 == 0) {
    n /= 2;
    p2++;
  }
  while (n && n % 5 == 0) {
    n /= 5;
    p5++;
  }
  return {p2 - p10, p5 - p10};
}
map<pll, ll> cntatleast;
void tc() {
  ll n, ans = 0;
  string x;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> x;
    v[i] = tofraction(x);
    for (ll n1 = -19; n1 <= v[i].first; n1++)
      for (ll n2 = -19; n2 <= v[i].second; n2++)
        cntatleast[{n1, n2}]++;
  }
  for (ll i = 0; i < n; i++) {
    ans += cntatleast[{-v[i].first, -v[i].second}] -
           (v[i].first >= 0 && v[i].second >= 0);
  }
  cout << ans / 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  // ll q; cin>>q; while(q--)
  tc();

  return 0;
}