Page 1 of 1

Why WA in DCP-241: Logic-Man

PostPosted: Sun Jun 18, 2017 8:56 pm
by khmahbub20
I am trying to solve DCP-241: Logic-Man problem . My code is as following :
Code: Select all
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<ctype.h>
#include<memory.h>

#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<iterator>

#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;

#define ll long long

#define pi 2*acos(0.0)
#define inf 1<<30
#define mod 1000000007

int a[100010];

int main()
{
    int t,c=1;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        int sum = 0;
        for(int i=0; i<n; i++) {
            cin >> a[i];
        }

        for (int i = 0; i < 32; i++)
        {
            int k = 0;
            for (int j = 0; j < n; j++)
                if ( !(a[j] & (1 << i)) )
                    k++;

            sum += (1<<i) * (n*(n-1)/2 - k*(k-1)/2);
        }

        cout << "Case " << c << ": " << sum << endl;
        c++;
    }

return 0;
}


Where is the error in my code ?
And a test case will be very helpful.

Re: Why WA in DCP-241: Logic-Man

PostPosted: Wed Jun 21, 2017 2:20 pm
by BishalG
Answer will exceeds integer. So, try to change datatype used for "sum" variable.

Re: Why WA in DCP-241: Logic-Man

PostPosted: Wed Jun 21, 2017 2:27 pm
by khmahbub20
Thanks