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

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  ll a[n];
  string s;
  ll dp[102][102], store[102][102];
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      dp[i][j] = 0;
      store[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    cin >> s;
    ll temp = 0;
    int index = -1;
    int p2 = 0, p5 = 0;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == '.') {
        index = j;
        continue;
      }
      temp = temp * 10 + (s[j] - '0');
    }
    if (index != -1) {
      p2 -= (s.length() - index - 1);
      p5 -= (s.length() - index - 1);
    }
    while (temp % 2 == 0) {
      temp /= 2;
      ++p2;
    }

    while (temp % 5 == 0) {
      temp /= 5;
      ++p5;
    }

    //	cout<<p2<<" "<<p5<<"\\n";

    ++dp[p2 + 50][p5 + 50];
    ++store[p2 + 50][p5 + 50];
  }
  for (int i = 100; i >= 0; i--) {
    for (int j = 100; j >= 0; j--) {
      dp[i][j] += (dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1]);
    }
  }

  /*		for(int i=0;i<=20;i++){
                  for(int j=0;j<=20;j++){
                          cout<<dp[i][j]<<" ";
                   }
                   cout<<"\\n";
             }*/
  ll ans = 0, ans1 = 0;
  for (int i = 0; i <= 100; i++) {
    for (int j = 0; j <= 100; j++) {
      int p2 = i - 50, p5 = j - 50;
      p2 = -p2, p5 = -p5;
      p2 += 50, p5 += 50;
      if (p2 < 0 || p5 < 0)
        continue;
      if (p2 <= i && p5 <= j) {
        ans += (store[i][j]) * (dp[p2][p5] - store[i][j]);
        ans1 += ((store[i][j]) * (store[i][j] - 1)) / 2;
      } else {
        ans += (store[i][j]) * (dp[p2][p5]);
      }
    }
  }
  ans /= 2;
  cout << ans + ans1 << "\\n";
  return 0;
}

Error: 0

Fixed submission:

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

int main() {
  //	ios_base::sync_with_stdio(false);
  //   cin.tie(NULL);
  int n;
  cin >> n;
  ll a[n];
  string s;
  ll dp[22][22], store[22][22];
  for (int i = 0; i <= 21; i++) {
    for (int j = 0; j <= 21; j++) {
      dp[i][j] = 0;
      store[i][j] = 0;
    }
  }

  for (int i = 0; i < n; i++) {
    cin >> s;
    ll temp = 0;
    int index = -1;
    int p2 = 0, p5 = 0;
    for (int j = 0; j < s.length(); j++) {
      if (s[j] == '.') {
        index = j;
        continue;
      }
      temp = temp * 10 + (s[j] - '0');
    }
    if (index != -1) {
      p2 -= (s.length() - index - 1);
      p5 -= (s.length() - index - 1);
    }
    while (temp % 2 == 0) {
      temp /= 2;
      ++p2;
    }

    while (temp % 5 == 0) {
      temp /= 5;
      ++p5;
    }

    //	cout<<p2<<" "<<p5<<"\\n";

    ++dp[p2 + 10][p5 + 10];
    ++store[p2 + 10][p5 + 10];
  }
  for (int i = 20; i >= 0; i--) {
    for (int j = 20; j >= 0; j--) {
      dp[i][j] += (dp[i + 1][j] + dp[i][j + 1] - dp[i + 1][j + 1]);
    }
  }

  /*		for(int i=0;i<=20;i++){
                  for(int j=0;j<=20;j++){
                          cout<<dp[i][j]<<" ";
                   }
                   cout<<"\\n";
             }*/
  ll ans = 0, ans1 = 0;
  for (int i = 0; i <= 20; i++) {
    for (int j = 0; j <= 20; j++) {
      int p2 = i - 10, p5 = j - 10;
      p2 = -p2, p5 = -p5;
      p2 += 10, p5 += 10;
      if (p2 <= i && p5 <= j) {
        ans += (store[i][j]) * (dp[p2][p5] - store[i][j]);
        ans1 += ((store[i][j]) * (store[i][j] - 1)) / 2;
      } else {
        ans += (store[i][j]) * (dp[p2][p5]);
      }
    }
  }
  ans /= 2;
  cout << ans + ans1 << "\\n";
  return 0;
}