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

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define PP pair<P, P>
using namespace std;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint &operator+=(const mint a) {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a) {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint &operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

#define P pair<ll, ll>

// 出力は.xで！！！！
/*
ll ni(ll a){
    if(a==0) return 1;
    else if(a%2==0) return ((ni(a/2)%MOD)*(ni(a/2)%MOD)%MOD);
    else return ((ni(a-1)%MOD)*2%MOD);
}
*/
int main() {
  int n;
  cin >> n;
  map<P, P> p;
  ll zero = 0;

  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    if (a == 0 && b == 0) {
      zero++;
      continue;
    }
    a /= g;
    b /= g;
    if (a == 0) {
      p[P(0, 1)].first++;
      continue;
    }
    if (b == 0) {
      p[P(0, 1)].second++;
      continue;
    }
    if (a > 0 && b > 0)
      p[P(a, b)].first++;
    if (a < 0 && b < 0)
      p[P(-a, -b)].first++;
    if (a > 0 && b < 0)
      p[P(-b, a)].second++;
    if (a < 0 && b > 0)
      p[P(b, -a)].second++;
  }

  mint ans = 1;

  for (auto m : p) {
    int f = m.second.first;
    int s = m.second.second;
    mint tmp = 1;
    tmp += mint(2).pow(f) - 1;
    tmp += mint(2).pow(s) - 1;
    ans *= tmp;
  }

  cout << (ans + zero - 1).x << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
typedef long long ll;
#define P pair<double, double>
#define PP pair<P, P>
using namespace std;

ll ni(ll a) {
  if (a == 0)
    return 1;
  else if (a % 2 == 0)
    return ((ni(a / 2) % MOD) * (ni(a / 2) % MOD) % MOD);
  else
    return ((ni(a - 1) % MOD) * 2 % MOD);
}

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

  ll ans = ni(n) - 1;
  map<double, int> p;
  map<double, int> visited;
  map<double, int> pas;
  vector<P> iwashi(n);
  rep(i, n) {
    cin >> iwashi[i].first >> iwashi[i].second;
    double f = (double)(iwashi[i].second / iwashi[i].first);
    iwashi[i].second = f;
    p[f]++;
  }
  rep(i, n) {
    double aim = -(double)1 / iwashi[i].second;
    // cout << aim << endl;
    visited[aim]++;
    if (pas[aim])
      continue;
    pas[iwashi[i].second]++;
    int num = p[aim];
    // cout << i << ' ' << aim << ' ' << num << endl;
    if (num) {
      rep(i, num) {
        ans -= ni(n - 1 - i - visited[aim]);
        ans %= MOD;
      }
    }
  }
  cout << ans << endl;
  return 0;
}