Submission #13358103


Source Code Expand

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL MOD = 1000000007;
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define debug(x) cout << #x << " : " << x << endl
#define part cout << "----------------------------------\n";
#define mp make_pair
#include <iostream>

#define fastinput                     \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);

LL POW(LL x, LL y)
{
    LL ans = 1;
    LL base = x;
    while (y)
    {
        if (y & 1)
        {
            ans *= base;
            ans %= MOD;
        }
        base = base * base;
        base %= MOD;
        y = y >> 1;
    }
    return ans;
}

int main()
{
    fastinput;
    LL n, i, j, k, t, temp, tc,mult,pos,neg;
    cin >> n;
    LL s_a,s_b;
    LL a[n + 1], b[n + 1];
    //zero case
    map<pair<LL, LL>, LL> freq;
    LL cnt_both = 0;
    LL neg_trouble = 0, pos_trouble = 0;
    set<pair<LL, LL>> s;
    for (i = 1; i <= n; i++)
    {
       // debug(i);
        cin >> a[i] >> b[i];
      //  debug(a[i]);
       // debug(b[i]);
        ///////////////////////////
        if (a[i] == 0 && b[i] == 0)
        {
            cnt_both++;
            continue;
        }
        /////////////////////

        if (b[i] == 0)
        {
            neg_trouble++;
        }
        else if (a[i] == 0)
        {
            pos_trouble++;
        }
        else
        {

            if(a[i]>0)
            {
                s_a=1;
            }
            else
            {
                s_a=-1;
            }

            if(b[i]>0)
            {
                s_b=1;
            }
            else
            {
                s_b=-1;
            }
            
            
            
            if (s_a*s_b> 0)
            {
                //positive
                LL hcf = __gcd((LL)fabs(a[i]), (LL)fabs(b[i]));
                LL num = fabs(a[i]) / hcf;
                LL denom = fabs(b[i]) / hcf;
                freq[{num, denom}]++;
              //  cout << "increenting for " << num << " " << denom << endl;
            }
            else
            {
                //negative
                LL hcf = __gcd((LL)fabs(a[i]), (LL)fabs(b[i]));
                LL num = -fabs(a[i]) / hcf;
                LL denom = fabs(b[i]) / hcf;
                freq[{num, denom}]++;
               // cout << "increenting for " << num << " " << denom << endl;
            }
        }
       // part;
    }

    LL other = 1;

    LL ans = cnt_both;
    for (auto x : freq)
    {
        //part;
        LL num = x.first.first;
        LL denom = x.first.second;
        LL num_abs = fabs(num);
        LL denom_abs = fabs(denom);
        LL parity = 1;
        if (num<0 && denom>0)
        {
            parity = -1;
        }
        if (denom<0 && num>0)
        {
            parity = -1;
        }
        if (s.find({num, denom}) == s.end())
        {

            pos = x.second;
            neg = 0;
            LL num_com = (-parity) * denom_abs;
            LL denom_com = num_abs;
            if (freq.find({num_com, denom_com}) == freq.end())
            {
                neg = 0;
            }
            else
            {
                neg = freq[{num_com, denom_com}];
            }

            s.insert({num, denom});
            s.insert({num_com, denom_com});
           // debug(num);
            //debug(denom);
            //debug(num_com);
           // debug(denom_com);
           // debug(pos);
           // debug(neg);
            mult = (((POW(2, pos) + POW(2, neg)) % MOD) - 1+MOD) % MOD + 100*MOD;
            mult %= MOD;
            if(mult<0)
            {
                LL tr=4/0;
            }
            //debug(mult);
            other *= mult;
            other %= MOD;
        }
        else
        {
           // cout << "skipping \n";
           // debug(num);
           // debug(denom);
        }

       // part;
    }

    ////////////////////////
    pos=pos_trouble;
    neg=neg_trouble;
    //debug(pos_trouble);
   // debug(neg_trouble);
    mult = (((POW(2, pos) + POW(2, neg)) % MOD) - 1+MOD) % MOD + MOD;
    mult %= MOD;
   // debug(mult);
    other *= mult;
    other %= MOD;
    //////////////////////

    other = ((other - 1) % MOD + MOD) % MOD;
    ans = (cnt_both + other) % MOD;
    //debug(ans);
    cout<<ans<<endl;

    return 0;
}

Submission Info

Submission Time
Task E - ∙ (Bullet)
User anmolagarwal999
Language C++ (GCC 9.2.1)
Score 0
Code Size 4580 Byte
Status WA
Exec Time 555 ms
Memory 44244 KiB

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:161:24: warning: division by zero [-Wdiv-by-zero]
  161 |                 LL tr=4/0;
      |                       ~^~
./Main.cpp:161:20: warning: unused variable ‘tr’ [-Wunused-variable]
  161 |                 LL tr=4/0;
      |                    ^~
./Main.cpp:38:14: warning: unused variable ‘j’ [-Wunused-variable]
   38 |     LL n, i, j, k, t, temp, tc,mult,pos,neg;
      |              ^
./Main.cpp:38:17: warning: unused variable ‘k’ [-Wunused-variable]
   38 |     LL n, i, j, k, t, temp, tc,mult,pos,neg;
      |                 ^
./Main.cpp:38:20: warning: unused variable ‘t’ [-Wunused-variable]
   38 |     LL n, i, j, k, t, temp, tc,mult,pos,neg;
      |                    ^
./Main.cpp:38:23: warning: unused variable ‘temp’ [-Wunused-variable]
   38 |     LL n, i, j, k, t, temp, tc,mult,pos,neg;
      |                       ^~~~
./Main.cpp:38:29: warning: unused variable ‘tc’ [-Wunused-variable]
   38 |     LL n, i, j, k, t, temp, tc,mult,pos,neg;
      |                             ^~

Judge Result

Set Name Sample Subtask1
Score / Max Score 0 / 0 0 / 500
Status
AC × 2
AC × 13
WA × 10
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
Subtask1 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 AC 5 ms 3588 KiB
sample_02.txt AC 2 ms 3508 KiB
sub1_01.txt AC 555 ms 44244 KiB
sub1_02.txt AC 2 ms 3604 KiB
sub1_03.txt AC 2 ms 3588 KiB
sub1_04.txt AC 2 ms 3620 KiB
sub1_05.txt AC 2 ms 3656 KiB
sub1_06.txt AC 2 ms 3532 KiB
sub1_07.txt AC 2 ms 3604 KiB
sub1_08.txt AC 2 ms 3608 KiB
sub1_09.txt AC 2 ms 3452 KiB
sub1_10.txt AC 2 ms 3456 KiB
sub1_11.txt WA 101 ms 13884 KiB
sub1_12.txt WA 274 ms 26888 KiB
sub1_13.txt WA 400 ms 32936 KiB
sub1_14.txt WA 203 ms 23028 KiB
sub1_15.txt WA 25 ms 5332 KiB
sub1_16.txt WA 218 ms 22628 KiB
sub1_17.txt WA 84 ms 11676 KiB
sub1_18.txt WA 276 ms 37784 KiB
sub1_19.txt WA 16 ms 4156 KiB
sub1_20.txt WA 52 ms 5688 KiB
sub1_21.txt AC 27 ms 6748 KiB