1917A - Least Product - CodeForces Solution


constructive algorithms math

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
#pragma GCC target("popcnt")
#define endl '\n'
#define F first
#define S second
#define Fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define Ok(x) x == true ?cout<<"Yes"<<endl : cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const int N = 1e6+30;
const int M = 1e9 + 7;
const int LOG = 27;
const ll INF = 1e18;
///////////////////////////////////////////////////////////////////
struct tt
{
    int F, S, T;
    tt() {}
    tt(int a,int b, int c)
    {
        F = a;
        S = b;
        T = c;
    }
    bool operator < (const tt & n) const
    {
        if( F == n.F )
        {
            return S > n.S;
        }
        return F < n.F;
    }

};
ll poww(ll x, ll n, ll mod = INF)
{
    if(x == 0) return 0 ;
    if(x == 1) return 1;
    if(n == 0) return 1 ;
    if(n == 1) return x%mod ;
    ll Ans = poww(x, n/2, mod)%mod ;
    Ans = (Ans * Ans)%mod;
    if(n%2) return (Ans *x) %mod ;
    return Ans ;
}
ll inv(ll x,ll mod)
{
    return poww(x, mod-2, mod)%mod ;
}
ll Gcd(ll x,ll y)
{
    return y ? Gcd(y,x%y) : x ;
}
ll fact[N];
void fac()
{
    fact[0]  =  1;
    for( ll i = 1 ; i < N ; i++ )
    {
        fact[i] = (fact[i-1]*i)%M;
    }
    return;
}
ll C(ll a, ll b)
{
    if(a-b<0)return 0LL;
    ll res = (fact[a]*inv(fact[b],M))%M;
    res = res*inv(fact[a-b],M)%M;
    return res;
}
int viss[2*N];
void seive()
{
    viss[1] = 0 ;
    viss[0] = 1;
    for( int i = 2 ; i < N ; i++ )
    {
        if(!viss[i])
        {
            for( int j = i ; j < N ; j += i  )
            {
                if(viss[j] == 0)
                    viss[j] = i;
            }
        }
    }
}
string toBinary(int x)
{
    string ret;
    while(x)
    {
        ret = ret +  char((x % 2) + '0');
        x /= 2;
    }
    reverse(ret.begin(), ret.end());
    return ret;
}
ll segma( ll x, ll y )
{
    ll res = ( y - x + 1 );
    res = res * ( x + y );
    res /= 2;
    return res;
}
int count(const string& s, const string& T)
{
    int cnt = 0;
    for (int i = 0; i < (int)s.size(); ++i)
    {
        if (s.substr(i, T.size()) == T)
        {
            ++cnt;
        }
    }
    return cnt;
}
ll maxSubArraySum(ll a[], int size)
{
    ll max_so_far = -INF, max_ending_here = 0, start = 0, end = 0, s = 0;
    for(int i = 1; i <= size; i++)
    {

        if( abs(a[i]%2) != abs(a[i-1]%2) )
        {
            max_ending_here = 0;
        }
        max_ending_here += a[i];
        if(max_so_far < max_ending_here)
        {
            max_so_far = max_ending_here;
        }
        if(max_ending_here < 0)
        {
            max_ending_here = 0;
        }
    }
    return  max_so_far;
}
template<typename S, typename T> S smax(S& a, const T& b)
{
    if(a < b) a = b;
    return a;
}
template<typename S, typename T> S smin(S& a, const T& b)
{
    if(a > b) a = b;
    return a;
}
int di[4] = { -1, 1, 0, 0 };
int dj[4] = { 0, 0, 1, -1 };
///////////////////////////////////////////////////////////////////
void Solve()
{
    int n;
    cin >> n;
    bool ok = false;
    int x = 0 ;
    vector < int > arr ( n + 1 , 0 );
    for ( int i = 1 ; i <= n ; i++ ){
        cin >> arr[i];
        if ( arr[i] == 0 ){
            ok = 1;
        }
        if ( arr[i] < 0 ){
            x++;
        }
    }
    if ( x % 2 ){
        cout << 0 << endl;
        return;
    }
    if ( ok ){
        cout << 0 << endl;
        return ;
    }
    cout << 1 << endl << 1 << ' ' << 0 << endl;
}
int main()
{
    Fast;
    /*freopen("input.txt","r" ,stdin );
    freopen("output.txt","w" ,stdout);*/
    int Test = 1 ;
    seive();
    cin >> Test;
Start:
    for(int test = 1 ; test <= Test ; test++ )
    {
        Solve();
    }
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

1302. Deepest Leaves Sum
1209. Remove All Adjacent Duplicates in String II
994. Rotting Oranges
983. Minimum Cost For Tickets
973. K Closest Points to Origin
969. Pancake Sorting
967. Numbers With Same Consecutive Differences
957. Prison Cells After N Days
946. Validate Stack Sequences
921. Minimum Add to Make Parentheses Valid
881. Boats to Save People
497. Random Point in Non-overlapping Rectangles
528. Random Pick with Weight
470. Implement Rand10() Using Rand7()
866. Prime Palindrome
1516A - Tit for Tat
622. Design Circular Queue
814. Binary Tree Pruning
791. Custom Sort String
787. Cheapest Flights Within K Stops
779. K-th Symbol in Grammar
701. Insert into a Binary Search Tree
429. N-ary Tree Level Order Traversal
739. Daily Temperatures
647. Palindromic Substrings
583. Delete Operation for Two Strings
518. Coin Change 2
516. Longest Palindromic Subsequence
468. Validate IP Address
450. Delete Node in a BST