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

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable ":\\t" << (variable) << endl
#define LOGCON(i, container)                                                   \\
  for (int(i) = 0; (i) < (container).size(); ++(i))                            \\
  cerr << (i) << ":\\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)       // from n to 0
#define REPRS(i, n, r) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj)                                                       \\
  for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj)                                                      \\
  for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template <typename T = int> T in() {
  T a;
  cin >> a;
  return a;
}
map<int, int> GetPrimeFactors(int n) {
  map<int, int> mp;
  // divide by 2, 3, 5, ...
  while (n % 2 == 0) {
    ++mp[2];
    n /= 2;
  }
  while (n % 5 == 0) {
    ++mp[5];
    n /= 5;
  }
  return mp;
}
/***** MAIN *****/
int counter_counter[20][20];
signed main() {
  int n;
  cin >> n;
  double tmp;
  int tmpi;
  map<int, int> mp;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    tmpi = tmp * 10000000000;
    if (tmpi % 10 == 9) {
      ++tmpi;
    }
    tmpi /= 10;
    mp = GetPrimeFactors(tmpi);
    int two = mp[2];
    int five = mp[5];
    if (two >= 18 && five >= 18) {
      ans += i;
    } else if (two >= 18) {
      for (int j = 0; j <= 18; ++j) {
        for (int k = max(0LL, 18 - five); k <= 18; ++k) {
          ans += counter_counter[j][k];
        }
      }
    } else if (five >= 18) {
      for (int j = max(0LL, 18 - two); j <= 18; ++j) {
        for (int k = 0; k <= 18; ++k) {
          ans += counter_counter[j][k];
        }
      }
    } else {
      for (int j = max(0LL, 18 - two); j <= 18; ++j) {
        for (int k = max(0LL, 18 - five); k <= 18; ++k) {
          ans += counter_counter[j][k];
        }
      }
    }
    ++counter_counter[min(18LL, two)][min(18LL, five)];
  }
  cout << ans;
  cout << "\\n";
  return 0;
}
/***** MAIN *****/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define int long long
using P = pair<int, int>;

#define LOG(variable) cerr << #variable ":\\t" << (variable) << endl
#define LOGCON(i, container)                                                   \\
  for (int(i) = 0; (i) < (container).size(); ++(i))                            \\
  cerr << (i) << ":\\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for (int i = (n); i >= 0; --i)       // from n to 0
#define REPRS(i, n, r) for (int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj)                                                       \\
  for (auto itr = (obj).begin(); itr != (obj).end(); ++itr)
#define REPROBJ(itr, obj)                                                      \\
  for (auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
template <typename T = int> T in() {
  T a;
  cin >> a;
  return a;
}
map<int, int> GetPrimeFactors(int n) {
  map<int, int> mp;
  // divide by 2, 3, 5, ...
  while (n % 2 == 0) {
    ++mp[2];
    n /= 2;
  }
  for (int i = 3; i * i <= n; i += 2) {
    while (n % i == 0) {
      ++mp[i];
      n /= i;
    }
  }
  if (n != 1)
    ++mp[n];

  return mp;
}
/***** MAIN *****/
int counter_counter[20][20];
signed main() {
  int n;
  cin >> n;
  double tmp;
  int tmpi;
  map<int, int> mp;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> tmp;
    tmpi = tmp * 10000000000;
    if (tmpi % 10 == 9) {
      ++tmpi;
    }
    tmpi /= 10;
    mp = GetPrimeFactors(tmpi);
    int two = mp[2];
    int five = mp[5];
    if (two >= 18 && five >= 18) {
      ans += i;
    } else if (two >= 18) {
      for (int j = 0; j <= 18; ++j) {
        for (int k = max(0LL, 18 - five); k <= 18; ++k) {
          ans += counter_counter[j][k];
        }
      }
    } else if (five >= 18) {
      for (int j = max(0LL, 18 - two); j <= 18; ++j) {
        for (int k = 0; k <= 18; ++k) {
          ans += counter_counter[j][k];
        }
      }
    } else {
      for (int j = max(0LL, 18 - two); j <= 18; ++j) {
        for (int k = max(0LL, 18 - five); k <= 18; ++k) {
          ans += counter_counter[j][k];
        }
      }
    }
    ++counter_counter[min(18LL, two)][min(18LL, five)];
  }
  cout << ans;
  cout << "\\n";
  return 0;
}
/***** MAIN *****/