Why WA in DCP-241: Logic-Man

Dev Skill archived problems can be discussed here.

Why WA in DCP-241: Logic-Man

by khmahbub20 » Sun Jun 18, 2017 8:56 pm

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.
 
Posts: 2
Joined: Sun Jun 18, 2017 8:49 pm

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

by BishalG » Wed Jun 21, 2017 2:20 pm

Answer will exceeds integer. So, try to change datatype used for "sum" variable.
User avatar
 
Posts: 29
Joined: Tue Jan 17, 2017 10:10 pm

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

by khmahbub20 » Wed Jun 21, 2017 2:27 pm

Thanks
 
Posts: 2
Joined: Sun Jun 18, 2017 8:49 pm


Who is online
Users browsing this forum: No registered users and 1 guest
cron