Pairwise AND sum

They have given the constraints, in the subtasks and had not told about the task. So, please tell me where we have to use these constraints, for what?

I have made a simple code for this question that is

and my solution is like this
#include <stdio.h>
int main()
{
long long int n;
scanf("%d", &n);
long long int A[n], i;
for(i=0; i<n; i++)
scanf("%d", &A[i]);
long long int sum=0, j;
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
sum+=A[i]&A[j];
}
}
printf("\n %d", sum);
return 0;
}

@optimus_prime1 problems in the School section are all partial marking problem. objective is same for all the subtasks but constraints are different you cannot use same algorithm for the subtasks 3 and 4 you have to do more for these subtasks to pass refer http://discuss.codechef.com/problems/AND

There are several other mistakes in your code for ex: you are declaring each variable as long long int but trying to read it using %d specifier change it to %lld then you will get the points for the subtaks 1 or 2. comment for any other help

hello optimus_prime1 i am bit busy right now but i will definately answer all your queries by todays evening and check out this for information on the data types and their ranges http://msdn.microsoft.com/en-IN/library/s3f49ktz.aspx

it depends upon the architecture of the machine dude first of all your code is perfect now but it can be more efficient .you are using the naive approach instead you can manipulate the property of AND as described in the editorial . using BIT manipulation this question can be solved in O(n*(log(max(A[i]))) which is equal to 20*(n) in the worst case according to the constraints mantioned in this problem so i request to have a look on the editorial then you can create your own variation of pair wise or or pair wise XOR even you can find these problem on some other online judge…:smiley:

if you still something to ask please comment :stuck_out_tongue:

if you like this ,feel free to cast votes

you can refer some solution which are making use of these approches

hey kid,
i dont have any problem if someone does not cast any vote even but this serve as a notification to me that someone is really interested in my answer now tell me what you want to ask now even i am not getting you where you are facing problem . i am ready to help you out just tell me the problem…:smiley:

These are constraints only, that can be done by using the formula given in the editorial.

@optimus_prime1 problems in the School section are all partial marking problem. objective is same for all the subtasks but constraints are different you cannot use same algorithm for the subtasks 3 and 4 you have to do more for these subtasks to pass
refer http://discuss.codechef.com/problems/AND

There are several other mistakes in your code for ex: you are declaring each variable as long long int but trying to read it using %d specifier change it to %lld then you will get the points for the subtaks 1 or 2.
comment for any other help

1 Like

hello optimus_prime1 i am bit busy right now but i will definately answer all your queries by today evening and check out this for information on the data types and their ranges http://msdn.microsoft.com/en-IN/library/s3f49ktz.aspx

I write the range of int, i.e., from -32768 to 32767, as according to the Computer Science Book, 11th, 12th class, Author: Sumita Arora.

What does Ai<=10 power 9 means? Does it means that each number of the array A, like 1, 2, 3, 4, 5, should be less than 10 power 9?

yes there are online coimpilers one such is ideone

i think this statement will just print the boolean values depending upon whether x>0 or not

hey i think you are just step a ladder in programming world right, first of all these problems are set such that even if you are not able to solve a problem completely even then you can get partial marks for that right. actually programming is all bout learning new things you know only this way of doing this question which is not very efficient but you can solve the same problem with greater efficiency right so that is the naive or brute force solution cannot be solved using your solution…

tell me for what i will give you a sample xplanation

for cpp

int A[1000];

for(int i=0;i<n;i++){

cin>>A[i];

}

for c

int A[1000],i;

for(i=0;i<n;i++){

scanf("%d",&A[i]);

}

sorry i did not get you that time there is some called stdin at the bottom just write input there in what ever format you want to write either seperated by new enter or by spaces

paste link of your ideone solution here

this is because we are using binary bits and to represent a number of val 10^9 we require at least log2(n) which is approximately equal to 30