alexjercan/bugnet huggingface dataset:
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

// https://atcoder.jp/contests/agc047/tasks/agc047_a
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

namespace mp = boost::multiprecision;
using cpp_dec = mp::cpp_dec_float_50;
using cpp_int = mp::cpp_int;
using namespace std;

#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define Aint(obj) (obj).begin(), (obj).end()
#define AintR(obj) (obj).rbegin(), (obj).rend()

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  map<pair<int, int>, int> cnt;
  REP(i, N) {
    cpp_dec x;
    cin >> x;
    int t = static_cast<int>(x * 1e9);
    // 2で割り切れる回数、5で割り切れる回数
    pair<int, int> p = {-9, -9};
    while (t % 2 == 0) {
      t /= 2;
      p.first++;
    }
    while (t % 5 == 0) {
      t /= 5;
      p.second++;
    }
    cnt[p]++;
  }
  // mapだと要素指定のアクセスができないのでvectorへ変換
  vector<pair<int, int>> ps;
  vector<int> cs;
  for (auto w : cnt) {
    ps.emplace_back(w.first);
    cs.emplace_back(w.second);
  }

  int ans = 0;
  REP(i, ps.size()) {
    pair<int, int> p = ps[i];
    if (p.first >= 0 && p.second >= 0) {
      ans += cs[i] * (cs[i] - 1) / 2;
    }
    REP(j, i) {
      if (p.first + ps[j].first >= 0 && p.second + ps[j].second >= 0) {
        ans += cs[i] * cs[j];
      }
    }
  }

  cout << ans << endl;
  return 0;
}


Error: TLE

Fixed submission:

// https://atcoder.jp/contests/agc047/tasks/agc047_a
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_dec_float.hpp>

namespace mp = boost::multiprecision;
using cpp_f = mp::cpp_dec_float_50;
using namespace std;

// #define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  vector<cpp_f> A(N);
  REP(i, N) { cin >> A[i]; }
  int ans = 0;
  REP(i, N) {
    FOR(j, i + 1, N) {
      cpp_f t = A[i] * A[j];
      // 切り上げした数と、切り捨てした数が同じなら整数とする
      if (mp::ceil(t) == mp::floor(t)) {
        ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll N = 1e9, D = 9;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto &e : a) {
    string s;
    cin >> s;
    ll x = 0, y = 0, d = 0;
    bool b = false;
    for (auto c : s) {
      if (c == '.') {
        b = true;
      } else if (b) {
        y *= 10;
        y += c - '0';
        d++;
      } else {
        x *= 10;
        x += c - '0';
      }
    }
    e = x * N + y * (ll)pow(10, D - d);
    // cerr << x << ' ' << y << ' ' << d << ' ' << e << endl;
  }

  vector<vector<ll>> m(50, vector<ll>(50));
  for (auto e : a) {
    int i = 0, j = 0;
    for (; e % 2 == 0; e /= 2)
      i++;
    for (; e % 5 == 0; e /= 5)
      j++;
    m[i][j]++;
  }

  ll r = 0;
  for (int i1 = 0; i1 < 50; i1++) {
    for (int j1 = 0; j1 < 50; j1++) {
      for (int i2 = 0; i2 < 50; i2++) {
        if (i1 + i2 < 2 * D)
          continue;
        for (int j2 = 0; j2 < 50; j2++) {
          if (j1 + j2 < 2 * D)
            continue;
          if (i1 == i2 && j1 == j2) {
            r += m[i1][j1] * (m[i1][j1] - 1);
          } else {
            r += m[i1][j1] * m[i2][j2];
          }
        }
      }
    }
  }
  r /= 2;
  cout << r << endl;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll N = 1e9, D = 9;

int main() {
  int n;
  cin >> n;
  vector<__int128> a(n);
  for (auto &e : a) {
    string s;
    cin >> s;
    ll x = 0, y = 0, d = 0;
    bool b = false;
    for (auto c : s) {
      if (c == '.') {
        b = true;
      } else if (b) {
        y *= 10;
        y += c - '0';
        d++;
      } else {
        x *= 10;
        x += c - '0';
      }
    }
    e = x * N + y * (ll)pow(10, D - d);
    // cerr << x << ' ' << y << ' ' << d << ' ' << e << endl;
  }

  ll r = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] * a[j] % (N * N) == 0)
        r++;
    }
  }
  cout << r << endl;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <map>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  map<pair<int, int>, int> cnt;
  int64_t ans = 0;
  for (int rep = 0; rep < n; rep++) {
    double x;
    cin >> x;
    int64_t i = llround(x * 1e9);
    int two = 0, five = 0;
    while (i % 2 == 0) {
      i /= 2;
      two++;
    }
    while (i % 5 == 0) {
      i /= 5;
      five++;
    }
    cnt[{two, five}]++;
  }
  for (auto p1 : cnt) {
    for (auto p2 : cnt) {
      if (p1.first.first + p2.first.first >= 18 &&
          p1.first.second + p2.first.second >= 18) {
        if (p1 < p2)
          ans += 1ll * p1.second * p2.second;
        else if (p1 == p2)
          ans += 1ll * p1.second * (p1.second - 1) / 2;
      }
    }
  }

  cout << ans << '\\n';
}

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <map>
using namespace std;

int main(void) {
  int n;
  cin >> n;
  map<pair<int, int>, int> cnt;
  int64_t ans = 0;
  for (int rep = 0; rep < n; rep++) {
    double x;
    cin >> x;
    int64_t i = llround(x * 1e9);
    int two = 0, five = 0;
    while (i % 2 == 0) {
      i /= 2;
      two++;
    }
    while (i % 5 == 0) {
      i /= 5;
      five++;
    }
    for (int a = 18 - two; a <= 30; a++) {
      for (int b = 18 - five; b <= 30; b++)
        ans += cnt[{a, b}];
    }
    cnt[{two, five}]++;
  }

  cout << ans << '\\n';
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

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

const int INF = 1000000000;
const int N = 50;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;

  vector<vector<int>> cnt(N, vector<int>(N));

  for (int i = 0; i < n; i++) {
    double x;
    cin >> x;

    int y = llround(x * INF);
    int two = 0;
    int five = 0;
    while (y % 2 == 0) {
      y /= 2;
      two++;
    }
    while (y % 5 == 0) {
      y /= 5;
      five++;
    }
    cnt[two][five]++;
  }

  int answer = 0;
  for (int two1 = 0; two1 < N; two1++) {
    for (int five1 = 0; five1 < N; five1++) {

      for (int two2 = 0; two2 < N; two2++) {
        for (int five2 = 0; five2 < N; five2++) {
          int tmp = 0;
          if (two1 + two2 >= 18 && five1 + five2 >= 18) {
            if (two1 == two2 && five1 == five2)
              tmp = cnt[two1][five1] * (cnt[two1][five1] - 1);
            else
              tmp = cnt[two1][five1] * cnt[two2][five2];
          }
          answer += tmp;
        }
      }
    }
  }

  cout << answer / 2 << '\\n';

  return 0;
}

Error: 0

Fixed submission:

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

const int INF = 1000000000;

const int N = 20;

signed main() {
  int n;
  cin >> n;

  vector<vector<int>> cnt(N, vector<int>(N));

  for (int i = 0; i < n; i++) {
    double x;
    cin >> x;

    int y = llround(x * INF);
    int two = 0;
    int five = 0;
    while (y % 2 == 0) {
      y /= 2;
      two++;
    }
    while (y % 5 == 0) {
      y /= 5;
      five++;
    }
    cnt[two][five]++;
  }

  int answer = 0;
  for (int two1 = 0; two1 < N; two1++) {
    for (int five1 = 0; five1 < N; five1++) {

      for (int two2 = 0; two2 < N; two2++) {
        for (int five2 = 0; five2 < N; five2++) {
          int tmp = 0;
          if (two1 + two2 >= 18 && five1 + five2 >= 18) {
            if (two1 == two2 && five1 == five2)
              tmp = cnt[two1][five1] * (cnt[two1][five1] - 1);
            else
              tmp = cnt[two1][five1] * cnt[two2][five2];
          }
          answer += tmp;
        }
      }
    }
  }

  cout << answer / 2 << '\\n';

  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

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

const int MAX = 50;

// 2D cumulative sum(座標は1-indexedであることに注意せよ)
int64_t sum[MAX][MAX];

int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> vec(N);
  for (int i = 0; i < N; i++) {
    long double x;
    cin >> x;
    x *= 1e9;
    vec[i] = round(x);
  }

  vector<int> T(N);
  vector<int> F(N);

  // 掛け算して10^18 = 2^18 * 5^18で割れれば良い

  for (int i = 0; i < N; i++) {
    int two = 0;
    int five = 0;
    int64_t x = vec[i];
    while (x % 2 == 0) {
      x /= 2;
      two++;
    }
    while (x % 5 == 0) {
      x /= 5;
      five++;
    }
    T[i] = two;
    F[i] = five;
    sum[two][five]++;
  }

  int64_t ans = 0;

  for (int i = 0; i < N; i++) {
    int64_t x = vec[i];
    for (int j = max(0, 18 - T[i]); j < MAX; j++) {
      for (int k = max(0, 18 - F[i]); k < MAX; k++) {
        ans += sum[j][k];
        if (j == T[i] && k == F[i]) {
          ans--;
        }
      }
    }
  }

  cout << ans / 2 << endl;
}

Error: 0

Fixed submission:

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

const int MAX = 100;

// 2D cumulative sum(座標は1-indexedであることに注意せよ)
int64_t sum[MAX][MAX];

int main() {
  int64_t N;
  cin >> N;
  vector<int64_t> vec(N);
  for (int i = 0; i < N; i++) {
    long double x;
    cin >> x;
    x *= 1e9;
    vec[i] = round(x);
  }

  // 掛け算して10^18 = 2^18 * 5^18で割れれば良い

  for (int i = 0; i < N; i++) {
    int two = 0;
    int five = 0;
    int64_t x = vec[i];
    while (x % 2 == 0) {
      x /= 2;
      two++;
    }
    while (x % 5 == 0) {
      x /= 5;
      five++;
    }
    sum[two][five]++;
  }

  int64_t ans = 0;

  for (int i = 0; i < N; i++) {
    int two = 0;
    int five = 0;
    int64_t x = vec[i];
    while (x % 2 == 0) {
      x /= 2;
      two++;
    }
    while (x % 5 == 0) {
      x /= 5;
      five++;
    }
    for (int j = 18 - two; j < MAX; j++) {
      for (int k = 18 - five; k < MAX; k++) {
        ans += sum[j][k];
        if (j == two && k == five) {
          ans--;
        }
      }
    }
  }

  cout << ans / 2 << endl;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <cmath>
#include <iostream>
#include <map>
#include <set>
using namespace std;

int main() {
  int n;
  scanf("%d", &n);
  map<pair<int, int>, set<int>> pair_index;
  for (int i = 0; i < n; i++) {
    double x;
    int pow2 = 0, pow5 = 0;
    unsigned long long val;
    scanf("%lf", &x);
    val = llround(x * 1e9);
    while (val % 2 == 0) {
      pow2++;
      val /= 2;
    }
    while (val % 5 == 0) {
      pow5++;
      val /= 5;
    }
    pair_index[*new pair(pow2, pow5)].insert(i);
  }
  unsigned long long counter = 0;
  for (auto i = pair_index.begin(); i != pair_index.end(); i++) {
    for (auto j = pair_index.begin(); j != pair_index.end(); j++) {
      if (min(i->first.first + j->first.first,
              i->first.second + j->first.second) >= 18) {
        if (i == j) {
          counter += i->second.size() * (j->second.size() - 1) / 2;
        } else if (*i < *j) {
          counter += (i->second.size() * j->second.size());
        }
      }
    }
  }
  printf("%llu\\n", counter);
  return 0;
}


Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
using namespace std;

struct num {
  unsigned long long pow2 = 0;
  unsigned long long pow5 = 0;
};

int main() {
  int n;
  scanf("%d", &n);
  num arr[n];
  double x;
  unsigned long long val;
  for (int i = 0; i < n; i++) {
    scanf("%lf", &x);
    val = llround(x * 1e9);
    while (val % 2 == 0) {
      arr[i].pow2++;
      val /= 2;
    }
    while (val % 5 == 0) {
      arr[i].pow5++;
      val /= 5;
    }
  }
  int counter = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (min(arr[i].pow2 + arr[j].pow2, arr[i].pow5 + arr[j].pow5) >= 18) {
        counter++;
      }
    }
  }
  printf("%d\\n", counter);
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<string> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  const int N2 = 50, N5 = 50;
  int z = 0;
  vector<vector<int>> dp(N2, vector<int>(N5));
  for (auto s : a) {
    bool dot = false;
    long long x = 0;
    int num = 0;
    for (int i = 0; i < (int)s.length(); i++) {
      if (s[i] == '.') {
        dot = true;
        continue;
      }
      if (dot)
        num++;
      x = 10 * x + (s[i] - '0');
    }
    num = 9 - num;
    while (num--)
      x *= 10;
    // cerr << x << '\\n';
    if (x % int(1e9) == 0)
      z++;

    int cnt2 = 0, cnt5 = 0;
    while (x % 2 == 0) {
      cnt2++;
      x /= 2;
    }
    while (x % 5 == 0) {
      cnt5++;
      x /= 5;
    }
    dp[cnt2][cnt5]++;
  }

  long long ans = 0;
  for (int i = 0; i < N2; i++) {
    for (int j = 0; j < N5; j++) {
      for (int x = 0; x < N2; x++) {
        for (int y = 0; y < N5; y++) {
          if (i + x >= 18 && j + y >= 18) {
            ans += 1LL * dp[i][j] * dp[x][y];
          }
        }
      }
    }
  }
  cerr << ans << ' ' << z << '\\n';
  ans = (ans - z) / 2;
  cout << ans << '\\n';

  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<double> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  const int N2 = 25, N5 = 16;
  int z = 0;
  vector<vector<int>> dp(N2, vector<int>(N5));
  for (auto i : a) {
    if (i == int(i))
      z++;
    long long x = i * 1e9;
    assert(x == (long long)x);
    int cnt2 = 0, cnt5 = 0;
    while (x % 2 == 0) {
      cnt2++;
      x /= 2;
    }
    while (x % 5 == 0) {
      cnt5++;
      x /= 5;
    }
    dp[cnt2][cnt5]++;
  }

  long long ans = 0;
  for (int i = 0; i < N2; i++) {
    for (int j = 0; j < N5; j++) {
      for (int x = 0; x < N2; x++) {
        for (int y = 0; y < N5; y++) {
          if (i + x >= 18 && j + y >= 18) {
            ans += 1LL * dp[i][j] * dp[x][y];
          }
        }
      }
    }
  }
  ans = (ans - z) / 2;
  cout << ans << '\\n';

  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  map<pair<int, int>, int> cnt;
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    ld x;
    cin >> x;
    x *= 1e9;
    ll y = x;
    ld d1 = fabs(y - x), d2 = fabs(y + 1 - x);
    if (d2 < d1) {
      y++;
    }
    int c2 = 0, c5 = 0;
    while (y % 2 == 0) {
      c2++;
      y /= 2;
    }
    while (y % 5 == 0) {
      c5++;
      y /= 5;
    }
    cnt[{c2, c5}]++;
  }
  ll sol = 0;
  for (auto &it1 : cnt) {
    for (auto &it2 : cnt) {
      if (it1 == it2) {
        if (it1.first.first + it2.first.first >= 18 &&
            it1.first.second + it2.first.second >= 18) {
          sol += (ll)it1.second * (it1.second - 1) / 2;
        }
        break;
      }
      if (it1.first.first + it2.first.first >= 18 &&
          it1.first.second + it2.first.second >= 18) {
        sol += (ll)it1.second * it2.second;
      }
    }
  }
  cout << sol << "\\n";
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
typedef long long ll;
typedef long double ld;

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<ll, ll>> v(n);
  for (int i = 0; i < n; i++) {
    ld x;
    cin >> x;
    x *= (ld)1e9;
    ll y = x;
    ld dif1 = fabs(y - x);
    ld dif2 = fabs(y + 1 - x);
    if (dif2 < dif1) {
      y++;
    }
    v[i] = {y, (ll)1e9};
  }
  for (auto &it : v) {
    ll g = __gcd(it.first, it.second);
    it.first /= g;
    it.second /= g;
  }
  vector<ll> a(n), b(n);
  ll sol = 0;
  for (int i = 0; i < n; i++) {
    a[i] = v[i].first;
    b[i] = v[i].second;
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (a[i] % b[j] == 0 && a[j] % b[i] == 0) {
        sol++;
      }
    }
  }
  cout << sol << "\\n";
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

using namespace std;

static const ll INF = 1e15;

int main() {
  int n;
  cin >> n;
  vector<vector<ll>> grid(20, vector<ll>(20, 0));
  vector<P> ss(n);
  rep(i, n) {
    double item;
    cin >> item;
    double t = item * 1e9 + 0.1;
    ll v = (ll)t;
    int a = 0;
    while (v % 2 == 0) {
      a++;
      v /= 2;
    }
    int b = 0;
    while (v % 5 == 0) {
      b++;
      v /= 5;
    }
    a = min(19, a);
    b = min(19, b);
    grid[a][b]++;
    ss[i] = make_pair(a, b);
  }

  ll sum = 0;
  rep(i, n) {
    auto f = ss[i].first;
    auto s = ss[i].second;
    grid[f][s]--;
    for (auto f2 = max(0LL, 18 - f); f2 < 20; f2++) {
      for (auto s2 = max(0LL, 18 - s); s2 < 20; s2++) {
        sum += grid[f2][s2];
      }
    }
  }

  cout << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>

#define M_PI 3.14159265358979323846 // pi

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> VI;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> t3;
typedef tuple<ll, ll, ll, ll> t4;
typedef tuple<ll, ll, ll, ll, ll> t5;

#define rep(a, n) for (ll a = 0; a < n; a++)
#define repi(a, b, n) for (ll a = b; a < n; a++)

using namespace std;

static const ll INF = 1e15;

int main() {
  int n;
  cin >> n;
  vector<vector<ll>> grid(20, vector<ll>(20, 0));
  vector<P> ss(n);
  rep(i, n) {
    double item;
    cin >> item;
    double t = item * 1e9 + 0.1;
    ll v = (ll)t;
    int a = 0;
    while (v % 2 == 0) {
      a++;
      v /= 2;
    }
    int b = 0;
    while (v % 5 == 0) {
      b++;
      v /= 5;
    }
    a = min(20, a);
    b = min(20, b);
    grid[a][b]++;
    ss[i] = make_pair(a, b);
  }

  ll sum = 0;
  rep(i, n) {
    auto f = ss[i].first;
    auto s = ss[i].second;
    grid[f][s]--;
    for (auto f2 = max(0LL, 18 - f); f2 < 20; f2++) {
      for (auto s2 = max(0LL, 18 - s); s2 < 20; s2++) {
        sum += grid[f2][s2];
      }
    }
  }

  cout << sum << endl;
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
long long kazu[30][30];
long long used[20][20][20][20];
int main() {
  int n;
  cin >> n;
  rep(i, n) {
    double x;
    cin >> x;
    long long xl = llround(x * 1e9);
    int ni = 0, go = 0;
    while (xl % 2 == 0) {
      ni++;
      xl /= 2;
    }
    while (xl % 5 == 0) {
      go++;
      xl /= 5;
    }
    if (ni >= 18)
      ni = 18;
    if (go >= 18)
      go = 18;
    kazu[ni][go]++;
    // cout<<kazu[ni][go]<<" "<<ni<<" "<<go<<endl;
  }
  long long kotae = 0;
  for (int i = 0; i <= 18; i++) {
    for (int j = 0; j <= 18; j++) {
      for (int k = 0; k <= 18; k++) {
        for (int l = 0; l <= 18; l++) {
          // if(i> k)break;
          if (kazu[i][j] >= 2 && i == k && j == l && i >= 9 && j >= 9) {
            if (used[i][j][i][j] == 0)
              kotae += kazu[i][j] * (kazu[i][j] - 1) / 2;
            used[i][j][i][j] = 1;
            // cout<<"b"<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<endl;
          } else if (kazu[i][j] >= 1 && kazu[k][l] >= 1 && i + k >= 18 &&
                     j + l >= 18) {
            if (i == k && j == l)
              continue;
            if (used[i][j][k][l] == 0)
              kotae += kazu[i][j] * kazu[k][l];
            used[k][l][i][j] = 1;
            used[i][j][k][l] = 1;
            // cout<<"a"<<kotae<<" "<<kazu[i][j]<<" "<<kazu[k][l]<<" "<<i<<"
            // "<<j<<" "<<k<<" "<<l<<" "<<endl;
          }
        }
      }
    }
  }
  cout << kotae << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  int n;
  cin >> n;
  vector<pair<long, long>> a(n);
  map<int, int> mp;
  rep(i, n) {
    double x;
    cin >> x;
    long long xl = llround(x * 1e9);
    int ni = 0, go = 0;
    while (xl % 2 == 0) {
      ni++;
      xl /= 2;
    }
    while (xl % 5 == 0) {
      go++;
      xl /= 5;
    }
    if (ni >= 19)
      ni = 19;
    if (go >= 19)
      go = 19;
    a[i].first = ni;
    a[i].second = go;
    // cout<<kazu[ni][go]<<" "<<ni<<" "<<go<<endl;
  }
  long long kotae = 0;
  bool hantei = false;
  rep(i, n - 1) {
    hantei = false;
    for (int j = i + 1; j < n; j++) {
      int b = a[i].first + a[j].first, c = a[i].second + a[j].second;
      int d = min(b, c);
      if (d >= 18)
        kotae++;
    }
  }
  cout << kotae << endl;
  return 0;
}
Problem p02588 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

int two(int64_t x) {
  int res = 0;
  while (x % 2 == 0) {
    x /= 2;
    res++;
  }
  return res;
}

int five(int64_t x) {
  int res = 0;
  while (x % 5 == 0) {
    x /= 5;
    res++;
  }
  return res;
}

int main(void) {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (s.find('.') == string::npos) {
      A[i] = stoll(s) * 1'000'000'000;
    } else {
      int d = s.size() - s.find('.');
      s += string(10 - d, '0');
      s.erase(s.find('.'), 1);
      A[i] = stoll(s);
    }
    // cerr << A[i] << endl;
  }

  map<pair<int, int>, int64_t> mp;
  for (int i = 0; i < N; i++) {
    // auto p = prime_factor(A[i]);
    mp[make_pair(two(A[i]), five(A[i]))]++;
  }

  int64_t ans = 0;
  for (int i = 0; i < N; i++) {
    int t = two(A[i]);
    int f = five(A[i]);
    // auto p = prime_factor(A[i]);
    for (auto [key, val] : mp) {
      if (t + key.first >= 18 && f + key.second >= 18) {
        ans += val;
      }
    }
    if (t >= 9 && f >= 9)
      --ans;
  }

  cout << ans / 2 << endl;
  return 0;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

map<int64_t, int> prime_factor(int64_t n) {
  map<int64_t, int> ret;
  for (int64_t i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

int main(void) {
  int N;
  cin >> N;
  vector<int64_t> A(N);
  for (int i = 0; i < N; i++) {
    string s;
    cin >> s;
    if (s.find('.') == string::npos) {
      A[i] = stoll(s) * 1'000'000'000;
    } else {
      int d = s.size() - s.find('.');
      s += string(10 - d, '0');
      s.erase(s.find('.'), 1);
      A[i] = stoll(s);
    }
    // cerr << A[i] << endl;
  }

  map<pair<int, int>, int64_t> mp;
  for (int i = 0; i < N; i++) {
    auto p = prime_factor(A[i]);
    mp[make_pair(p[2], p[5])]++;
  }

  int64_t ans = 0;
  for (int i = 0; i < N; i++) {
    auto p = prime_factor(A[i]);
    for (auto [key, val] : mp) {
      if (p[2] + key.first >= 18 && p[5] + key.second >= 18) {
        ans += val;
      }
    }
    if (p[2] >= 9 && p[5] >= 9)
      --ans;
  }

  cout << ans / 2 << endl;
  return 0;
}