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

#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(), a.end())
#define ll long long

using namespace std;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265359
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

const ll inf = 1000000007;
typedef pair<ll, ll> Pair;

typedef vector<ll> vl;

void csolve() {
  long double a, b;
  cin >> a >> b;
  kaku(floor(a * b));

  // printf("%.12f\\n",ans);
}

void bsolve() {
  ll n;
  cin >> n;

  ll t = 1000000000000000000;
  ll ans = 1;
  bool u = false; // t超えた？
  bool ok = true; // ０が出たか
  rep(i, n) {
    ll a;
    cin >> a;

    if (ans != 0) {
      if (t / ans < a)
        u = true;
    }

    ans *= a;

    if (a == 0)
      ok = false;
  }
  if (u && ok)
    ans = -1;
  kaku(ans);
}

void asolve() {
  ll a, b;
  cin >> a >> b;
  kaku(a * b);
}

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

void dsolve() {
  ll n;
  cin >> n;
  map<ll, ll> mp = prime_factor(n);
  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {

    for (ll i = 1; i <= 60; i++) {
      if (itr->second >= i) {
        mp[itr->first] -= i;
        ans++;
      } else {
        break;
      }
    }
  }
  kaku(ans);
}

int main() { bsolve(); }

Error: 0

Fixed submission:

#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#define pb push_back
#define make make_pair
#define kaku(a) cout << a << endl
#define isort(a) sort(a.begin(), a.end())
#define ll long long

using namespace std;

#define rep(i, n) for (ll i = 0; i < n; i++)
#define PI 3.14159265359
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }

const ll inf = 1000000007;
typedef pair<ll, ll> Pair;

typedef vector<ll> vl;

void csolve() {
  long double a, b;
  cin >> a >> b;
  kaku(floor(a * b));

  // printf("%.12f\\n",ans);
}

void bsolve() {
  ll n;
  cin >> n;

  ll t = 1000000000000000000;
  ll ans = 1;
  bool u = false;
  bool ok = true;
  rep(i, n) {
    ll a;
    cin >> a;

    if (a != 0) {
      if (t / ans < a)
        u = true;
    }

    ans *= a;

    if (a == 0)
      ok = false;
  }
  if (u && ok)
    ans = -1;
  kaku(ans);
}

void asolve() {
  ll a, b;
  cin >> a >> b;
  kaku(a * b);
}

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

void dsolve() {
  ll n;
  cin >> n;
  map<ll, ll> mp = prime_factor(n);
  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {

    for (ll i = 1; i <= 60; i++) {
      if (itr->second >= i) {
        mp[itr->first] -= i;
        ans++;
      } else {
        break;
      }
    }
  }
  kaku(ans);
}

int main() { bsolve(); }