Problem p02588 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 102;

int a[N][N];

int solv() {
  int q;
  scanf("%d", &q);
  while (q--) {
    char s[20];
    scanf(" %s", s);
    int n = strlen(s);

    ll x = 0;

    bool z = false;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '.') {
        int q = 9 - (n - i - 1);
        for (i = i + 1; i < n; ++i) {
          x = x * 10 + s[i] - '0';
        }
        while (q--) {
          x = x * 10;
        }
        z = true;
        break;
      }
      x = x * 10 + s[i] - '0';
    }
    if (!z) {
      for (int i = 0; i < 9; ++i)
        x = x * 10;
    }
    int q2 = 0;
    int q5 = 0;
    while (x % 2 == 0) {
      ++q2;
      x /= 2;
    }
    while (x % 5 == 0) {
      ++q5;
      x /= 5;
    }
    a[q2][q5]++;
  }
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (!a[i][j])
        continue;
      for (int i1 = 0; i1 < N; ++i1) {
        for (int j1 = 0; j1 < N; ++j1) {
          if (min(i + i1, j + j1) >= 18) {
            if (!(i == i1 && j == j1))
              ans += a[i][j] * 1LL * a[i1][j1];
            else
              ans += (a[i][j] * 1LL * a[i][j] - a[i][j]);
          }
        }
      }
    }
  }
  ans /= 2;
  printf("%lld\n", ans);
}

int main() {
#ifdef SOMETHING
  freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // SOMETHING
  // ios_base::sync_with_stdio(false), cin.tie(0);
  solv();
  return 0;
}

// while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define fi first
#define se second
typedef long long ll;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937 rnf(2106);
const int N = 102;

int a[N][N];

void solv() {
  int q;
  scanf("%d", &q);
  while (q--) {
    char s[20];
    scanf(" %s", s);
    int n = strlen(s);

    ll x = 0;

    bool z = false;
    for (int i = 0; i < n; ++i) {
      if (s[i] == '.') {
        int q = 9 - (n - i - 1);
        for (i = i + 1; i < n; ++i) {
          x = x * 10 + s[i] - '0';
        }
        while (q--) {
          x = x * 10;
        }
        z = true;
        break;
      }
      x = x * 10 + s[i] - '0';
    }
    if (!z) {
      for (int i = 0; i < 9; ++i)
        x = x * 10;
    }
    int q2 = 0;
    int q5 = 0;
    while (x % 2 == 0) {
      ++q2;
      x /= 2;
    }
    while (x % 5 == 0) {
      ++q5;
      x /= 5;
    }
    a[q2][q5]++;
  }
  ll ans = 0;
  for (int i = 0; i < N; ++i) {
    for (int j = 0; j < N; ++j) {
      if (!a[i][j])
        continue;
      for (int i1 = 0; i1 < N; ++i1) {
        for (int j1 = 0; j1 < N; ++j1) {
          if (min(i + i1, j + j1) >= 18) {
            if (!(i == i1 && j == j1))
              ans += a[i][j] * 1LL * a[i1][j1];
            else
              ans += (a[i][j] * 1LL * a[i][j] - a[i][j]);
          }
        }
      }
    }
  }
  ans /= 2;
  printf("%lld\n", ans);
}

int main() {
#ifdef SOMETHING
  freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif // SOMETHING
  // ios_base::sync_with_stdio(false), cin.tie(0);
  solv();
  return 0;
}

// while ((double)clock() / CLOCKS_PER_SEC <= 0.9){}