Problem p02588 (C++) — buggy submission, verdict: Runtime Error

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine()                                                          \\
  int endtime = clock();                                                       \\
  cerr << endl                                                                 \\
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC      \\
       << " ms";                                                               \\
  return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
                                  Container const &x) {
  os << "{ ";
  for (auto &y : x)
    os << y << ", ";
  return os << "}";
}

template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
  return os << "[ " << p.first << ", " << p.second << " ]";
}

#define debug(stuff) cout << #stuff << ": " << stuff << endl
#define debugc(stuff)                                                          \\
  cout << #stuff << ": ";                                                      \\
  for (auto x : stuff)                                                         \\
    cout << x << " ";                                                          \\
  cout << endl;
//

#define loop(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()

#define print(stuff) cout << stuff << endl
#define printc(stuff)                                                          \\
  for (auto x : stuff)                                                         \\
    cout << x << " ";                                                          \\
  cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return

#define ll long long
#define ld long double
#define fi first
#define endl '\\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
#define sz(a) (ll)(a).size()

#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int)1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5 + 5
#define N (1ll << 10)
#define pi 3.141592653589793238462643

void solve() {
  ll n;
  cin >> n;
  ld a[n];
  loop(i, 0, n) cin >> a[i];
  ll ans = 0;
  map<pll, ll> pow;
  pll p[n];
  loop(i, 0, n) {
    a[i] = llround(a[i] * 1e10);
    ll x = a[i];
    // trace(x);
    ll t = 0, f = 0;
    while (x % 2 == 0) {
      x = x / 2;
      t++;
    }
    // trace(x);
    while (x % 5 == 0) {
      x = x / 5;
      f++;
    }
    t -= 10;
    f -= 10;
    p[i] = mp(t, f);
    assert(t >= -10 && t <= 50 && f <= 50 && f >= -10);
    // trace (t, f);
    pow[mp(t, f)]++;
  }

  for (ll i = -10; i <= 50; i++) {
    for (ll j = -10; j <= 50; j++) {
      ll val1 = pow[mp(i, j)];
      ll val2 = 0;
      for (ll k = -10; k <= 50; k++) {
        for (ll l = -10; l <= 50; l++) {
          if (i + k >= 0 && l + j >= 0 && mp(i, j) != mp(k, l)) {
            val2 += pow[mp(k, l)];
          }
        }
      }
      if (i + i >= 0 && j + j >= 0)
        val2 += (pow[mp(i, j)] - 1);
      ans += val1 * val2;
    }
  }

  // for(ll i = 0; i < n; i++){
  //     ll val = 0;
  //     ll t = p[i].fi, f = p[i].se;
  //     for(ll k = -10; k <= 10; k++){
  //         for(ll l = -10; l <= 10; l++){
  //             if(t + k >= 0 && f + l >= 0 && mp(t, f) != mp(k, l)){
  //                 val += pow[mp(k, l)];
  //             }
  //         }
  //     }
  //     if(t >= 0 && f >= 0) val += pow[mp(t, f)] - 1;
  //     ans += val;
  // }

  print(ans / 2);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  start_routine();
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }

#ifndef ONLINE_JUDGE
  end_routine();
#endif
}


Error: TLE

Fixed submission:

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

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define start_routine() int begtime = clock();
#define end_routine()                                                          \\
  int endtime = clock();                                                       \\
  cerr << endl                                                                 \\
       << "Time elapsed: " << (endtime - begtime) * 1000 / CLOCKS_PER_SEC      \\
       << " ms";                                                               \\
  return 0
#define speed() cin.tie(0), cout.tie(0), ios_base::sync_with_stdio(false)
// #define exit(a, b) return cout << a, b;

// debugger
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char *name, Arg1 &&arg1) {
  cout << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cout.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}

template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os,
                                  Container const &x) {
  os << "{ ";
  for (auto &y : x)
    os << y << ", ";
  return os << "}";
}

template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p) {
  return os << "[ " << p.first << ", " << p.second << " ]";
}

#define debug(stuff) cout << #stuff << ": " << stuff << endl
#define debugc(stuff)                                                          \\
  cout << #stuff << ": ";                                                      \\
  for (auto x : stuff)                                                         \\
    cout << x << " ";                                                          \\
  cout << endl;
//

#define loop(i, a, b) for (ll i = a; i < b; i++)
#define all(v) v.begin(), v.end()

#define print(stuff) cout << stuff << endl
#define printc(stuff)                                                          \\
  for (auto x : stuff)                                                         \\
    cout << x << " ";                                                          \\
  cout << endl;
#define printPrec(stuff) cout << fixed << setprecision(15) << stuff << endl;
#define len length
#define ret0 return 0
#define ret return

#define ll long long
#define ld long double
#define fi first
#define endl '\\n'
#define se second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define fill(ar, x) memset(ar, x, sizeof ar)
#define sz(a) (ll)(a).size()

#define vl vector<ll>
#define sl set<ll>
#define pll pair<ll, ll>
#define mll map<ll, ll>
#define pq priority_queue<ll>

// typedef tree<ll,null_type,less<ll>,rb_tree_tag,
// tree_order_statistics_node_update> indexed_set;

#define inf (long long int)1e18
#define eps 0.000001
#define mod 1000000007
#define mod1 998244353
#define MAXN (ll)2e5 + 5
#define N (1ll << 10)
#define pi 3.141592653589793238462643

void solve() {
  ll n;
  cin >> n;
  ld a[n];
  loop(i, 0, n) cin >> a[i];
  ll ans = 0;
  map<pll, ll> pow;
  pll p[n];
  loop(i, 0, n) {
    a[i] = a[i] * (1e10);
    ll x = a[i];
    // trace(x);
    ll t = 0, f = 0;
    while (x % 2 == 0) {
      x = x / 2;
      t++;
    }
    // trace(x);
    while (x % 5 == 0) {
      x = x / 5;
      f++;
    }
    t -= 10;
    f -= 10;
    p[i] = mp(t, f);
    assert(t >= -10 && t <= 10 && f <= 10 && f >= -10);
    // trace (t, f);
    pow[mp(t, f)]++;
  }

  for (ll i = -10; i <= 50; i++) {
    for (ll j = -10; j <= 50; j++) {
      ll val1 = pow[mp(i, j)];
      ll val2 = 0;
      for (ll k = -10; k <= 50; k++) {
        for (ll l = -10; l <= 50; l++) {
          if (i + k >= 0 && l + j >= 0 && mp(i, j) != mp(k, l)) {
            // if(i == 0 && j == 0){
            //     trace(i, j, k, l);
            // }
            // trace(i, j, k, l);
            val2 += pow[mp(k, l)];
          }
        }
      }
      if (i + i >= 0 && j + j >= 0)
        val2 += pow[mp(i, j)] - 1;
      // if(val1 > 0 && val2 > 0) trace(i, j, val1, val2);
      ans += val1 * val2;
    }
  }

  // for(ll i = 0; i < n; i++){
  //     ll val = 0;
  //     ll t = p[i].fi, f = p[i].se;
  //     for(ll k = -10; k <= 10; k++){
  //         for(ll l = -10; l <= 10; l++){
  //             if(t + k >= 0 && f + l >= 0 && mp(t, f) != mp(k, l)){
  //                 val += pow[mp(k, l)];
  //             }
  //         }
  //     }
  //     if(t >= 0 && f >= 0) val += pow[mp(t, f)] - 1;
  //     ans += val;
  // }

  print(ans / 2);
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  start_routine();
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif

  ll t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }

#ifndef ONLINE_JUDGE
  end_routine();
#endif
}