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

#include <bits/stdc++.h>
#define ll long long
// #define endl "\\n"
#define pb push_back
#define ms(v, x) memset(v, x, sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(), v.end()
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define re(v)                                                                  \\
  {                                                                            \\
    for (auto &_re : v)                                                        \\
      cin >> _re;                                                              \\
  }
#define rre(v)                                                                 \\
  {                                                                            \\
    for (auto &_re : v)                                                        \\
      for (auto &_rre : _re)                                                   \\
        cin >> _rre;                                                           \\
  }
#define pr(v)                                                                  \\
  {                                                                            \\
    for (auto _pr : v)                                                         \\
      cout << _pr << " ";                                                      \\
    cout << endl;                                                              \\
  }
#define prr(v)                                                                 \\
  {                                                                            \\
    for (auto _prr : v)                                                        \\
      cout << _prr.ff << " " << _prr.ss << endl;                               \\
  }
#define eb emplace_back
using namespace std;
const ll M = 1e9 + 7;
const ll mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n;
  cin >> n;
  map<pii, int> m;
  string s;
  ll x, ans = 0;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> s;
    string y;
    x = -1;
    a = 0;
    b = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == '.') {
        while (j + 1 < s.size()) {
          j++;
          y.pb(s[j]);
          a--;
          b--;
        }
      } else {
        y.pb(s[j]);
      }
    }
    x = stoll(y);
    while (x % 10 == 0) {
      x /= 10LL;
      a++;
      b++;
    }
    while (x % 2 == 0) {
      a++;
      x /= 2LL;
    }
    while (x % 5 == 0) {
      b++;
      x /= 5LL;
    }
    for (int dx = -a; dx <= 25; dx++) {
      for (int dy = -b; dy <= 25; dy++) {
        auto it = m.find({dx, dy});
        if (it != m.end())
          ans += it->ss;
      }
    }
    m[{a, b}]++;
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
#define ll long long
// #define endl "\\n"
#define pb push_back
#define ms(v, x) memset(v, x, sizeof(v))
#define ff first
#define ss second
#define td(v) v.begin(), v.end()
#define rep(i, a, n) for (int i = (a); i < (n); i++)
#define pii pair<int, int>
#define pll pair<ll, ll>
#define re(v)                                                                  \\
  {                                                                            \\
    for (auto &_re : v)                                                        \\
      cin >> _re;                                                              \\
  }
#define rre(v)                                                                 \\
  {                                                                            \\
    for (auto &_re : v)                                                        \\
      for (auto &_rre : _re)                                                   \\
        cin >> _rre;                                                           \\
  }
#define pr(v)                                                                  \\
  {                                                                            \\
    for (auto _pr : v)                                                         \\
      cout << _pr << " ";                                                      \\
    cout << endl;                                                              \\
  }
#define prr(v)                                                                 \\
  {                                                                            \\
    for (auto _prr : v)                                                        \\
      cout << _prr.ff << " " << _prr.ss << endl;                               \\
  }
#define eb emplace_back
using namespace std;
const ll M = 1e9 + 7;
const ll mod = 998244353;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  int n;
  cin >> n;
  map<pii, int> m;
  string s;
  ll x, ans = 0;
  int a, b;
  for (int i = 0; i < n; i++) {
    cin >> s;
    string y;
    x = -1;
    a = 0;
    b = 0;
    for (int j = 0; j < s.size(); j++) {
      if (s[j] == '.') {
        while (j + 1 < s.size()) {
          j++;
          y += s[j];
          a--;
          b--;
        }
      } else {
        y += s[j];
      }
    }
    x = stoll(y);
    while (x % 10 == 0) {
      x /= 10;
      a++;
      b++;
    }
    while (x % 2 == 0) {
      a++;
      x /= 2;
    }
    while (x % 5 == 0) {
      b++;
      x /= 5;
    }
    for (int dx = -a; dx <= 20; dx++) {
      for (int dy = -b; dy <= 20; dy++) {
        ans += m[{dx, dy}];
      }
    }
    m[{a, b}]++;
  }
  cout << ans << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
}