Submission #13348648


Source Code Expand

Copy
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
template<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;
ll gcd(ll a, ll b) { return a ? gcd(b % a, a) : b; }
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan0
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N;
ll A[201010], B[201010];
//---------------------------------------------------------------------------------------------------
pair<ll, ll> rev(pair<ll, ll> x) {
    ll a = -x.first;
    ll b = x.second;

    if (a < 0) return make_pair(-b, -a);
    return make_pair(b, a);
}
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i] >> B[i];

    int zero_zero = 0;
    int zero_no = 0;
    int no_zero = 0;
    map<pair<ll, ll>,int> cnt;

    rep(i, 0, N) {
        if (A[i] == 0 && B[i] == 0) zero_zero++;
        else if (A[i] == 0) zero_no++;
        else if (B[i] == 0) no_zero++;
        else {
            ll g = gcd(abs(A[i]), abs(B[i]));
            A[i] /= g;
            B[i] /= g;
            if (B[i] < 0) {
                A[i] *= -1;
                B[i] *= -1;
            }
            cnt[make_pair(A[i], B[i])]++;
        }
    }

    mint ans = (mint(2) ^ zero_no) + (mint(2) ^ no_zero) - 1;
    set<pair<ll, ll>> used;
    fore(cn, cnt) if(!used.count(cn.first)) {
        auto p = cn.first;
        auto pp = rev(p);
        if (cnt.count(pp)) {
            ans *= (mint(2) ^ cnt[p]) + (mint(2) ^ cnt[pp]) - 1;
            used.insert(pp);
        }
        else {
            ans *= mint(2) ^ cnt[p];
        }
    }

    ans += zero_zero;
    ans -= 1;
    cout << ans << endl;
}





Submission Info

Submission Time
Task E - ∙ (Bullet)
User hamayanhamayan
Language C++ (GCC 9.2.1)
Score 500
Code Size 4472 Byte
Status
Exec Time 320 ms
Memory 19248 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt
Subtask1 500 / 500 sample_01.txt, sample_02.txt, sub1_01.txt, sub1_02.txt, sub1_03.txt, sub1_04.txt, sub1_05.txt, sub1_06.txt, sub1_07.txt, sub1_08.txt, sub1_09.txt, sub1_10.txt, sub1_11.txt, sub1_12.txt, sub1_13.txt, sub1_14.txt, sub1_15.txt, sub1_16.txt, sub1_17.txt, sub1_18.txt, sub1_19.txt, sub1_20.txt, sub1_21.txt
Case Name Status Exec Time Memory
sample_01.txt 5 ms 3664 KB
sample_02.txt 2 ms 3584 KB
sub1_01.txt 320 ms 19248 KB
sub1_02.txt 2 ms 3580 KB
sub1_03.txt 2 ms 3580 KB
sub1_04.txt 2 ms 3584 KB
sub1_05.txt 2 ms 3564 KB
sub1_06.txt 3 ms 3628 KB
sub1_07.txt 2 ms 3628 KB
sub1_08.txt 2 ms 3664 KB
sub1_09.txt 2 ms 3508 KB
sub1_10.txt 2 ms 3624 KB
sub1_11.txt 43 ms 5112 KB
sub1_12.txt 91 ms 6920 KB
sub1_13.txt 128 ms 8292 KB
sub1_14.txt 77 ms 6872 KB
sub1_15.txt 21 ms 4252 KB
sub1_16.txt 83 ms 6656 KB
sub1_17.txt 49 ms 5112 KB
sub1_18.txt 68 ms 6520 KB
sub1_19.txt 28 ms 6068 KB
sub1_20.txt 93 ms 11168 KB
sub1_21.txt 25 ms 6792 KB