Codeforces 1206B Make Product Equal One Solution

Solve in C++:

///AH Tonmoy
///Department of CSE
///Islamic University,Bangladesh
#include<bits/stdc++.h>
using namespace std;
int main()
{

    long long int ar[100001]= {0},n,i,o=0,sn=0,sp=0,s=0,ne=0,pos=0,r=0;
    cin>>n;
    {
        for(i=0; i<n; i++)
        {
            cin>>ar[i];
            if(ar[i]>0)
            {
                s=s+abs(ar[i])-1;
                 pos++;
            }

            else if(ar[i]<0)
            {
                s=s+(abs(ar[i])-1);
                 ne++;

            }
            else if(ar[i]==0)
            {
                s=s+1;
                o++;
            }
        }
        if((o==0)&&(ne%2!=0))
            cout<<s+2<<endl;
        else
        cout<<s<<endl;
    }
}

No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h ...

Powered by Blogger.