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

// Coded by Abhijay Mitra
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <vector>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb emplace_back
#define koto_memory(a) cout << (sizeof(a) / 1048576.0) << " MB";
#define res(v) sort(all(v)), v.erase(unique(all(v)), v.end());
#define timer                                                                  \\
  cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \\n";
#define deb(x) cout << "\\n[" << #x << " = " << x << "]\\n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int, int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, b, a) for (int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 2e6 + 10;
const int inf = /*0x3f3f3f3f*/ 1e18 + 10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
int n, z, cnt;
double tmp;
void solve() {
  cin >> n;
  map<pii, int> m;
  rep(i, 1, n) {
    cin >> tmp;
    int c1 = 0, c2 = 0;
    z = llround(tmp * 1e9);
    while ((z % 2) == 0)
      z /= 2, c1++;
    while ((z % 5) == 0)
      z /= 5, c2++;
    m[mp(c1, c2)]++;
  }
  for (auto i : m)
    for (auto j : m) {
      if (i < j) {
        if (i.F.F + j.F.F >= 18 and i.F.S + j.F.S >= 18)
          cnt += i.S * j.S;
      }
      if (i == j) {
        if (i.F.F + j.F.F >= 18 and i.F.S + j.F.S >= 18)
          cnt += i.S * (j.S - 1) / 2;
      }
    }
  cout << cnt;
}
int32_t main() {
  ibs;
  cti;
  solve();
  return 0;
  /*,cout<<"\\n"*/;
  // cout<<"\\n";
  int xx = 0;
  int t;
  cin >> t;
  while (t--) { /*xx++;cout<<"Case "<<xx<<":\\n"*/
    ;
    solve();
    cout << "\\n";
  }
  return 0;
}

Error: TLE

Fixed submission:

// Coded by Abhijay Mitra
#include <algorithm>
#include <bitset>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iterator>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdlib.h>
#include <vector>
// #include <bits/stdc++.h>
#define double long double
#define int long long int
#define ll int
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define bp __builtin_popcount
#define pb emplace_back
#define koto_memory(a) cout << (sizeof(a) / 1048576.0) << " MB";
#define res(v) sort(all(v)), v.erase(unique(all(v)), v.end());
#define timer                                                                  \\
  cerr << "Time elapsed : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \\n";
#define deb(x) cout << "\\n[" << #x << " = " << x << "]\\n";
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using pii = std::pair<int, int>;
using vpii = std::vector<pii>;
using vvpii = std::vector<vpii>;
#define mp make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, b, a) for (int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
using namespace std;
const int N = 2e6 + 10;
const int inf = /*0x3f3f3f3f*/ 1e18 + 10;
// const ll M = 998244353 ; // Mulo
// const int M = 1e9+7 ; // Mulo
const double Pi = 3.14159265;
#define F first
#define S second
double a[N], b[N];
int n;
void solve() {
  cin >> n;
  int cnt = 0;
  map<double, int> m;
  rep(i, 1, n) {
    cin >> a[i];
    m[a[i]]++;
  }
  rep(i, 1, n) {
    b[i] = (1 / a[i]);
    for (double j = 2 * b[i]; j < 1e4; j += b[i])
      cnt += m[j];
    if (m[a[i]] > 1)
      cnt += m[a[i]] - 1, m[a[i]]--;
  }
  cout << cnt;
}
int32_t main() {
  ibs;
  cti;
  solve();
  return 0;
  /*,cout<<"\\n"*/;
  // cout<<"\\n";
  int xx = 0;
  int t;
  cin >> t;
  while (t--) { /*xx++;cout<<"Case "<<xx<<":\\n"*/
    ;
    solve();
    cout << "\\n";
  }
  return 0;
}