 # Getting Wrong answer in Help Bob

My solution

https://www.codechef.com/viewsolution/42134323

Really cant figure out whats wrong in my solution
.Please help https://www.codechef.com/viewsolution/42140482

same soln but still my soln gives WA

my solution is also same I am getting wrong answer

one more thing -> Is these problems are availabe for practice???

nope not yet but I dont think so they will be available but I guess u should tag the problem setter here maybe he might add them here

@pro_army will questions will be available for practice.

Heres my solution:

#include<bits/stdc++.h>
using namespace std;

const int N = 1e6;
long arr[N];

int main() {

``````	int n, k;
cin>>n>>k;

int ele = 0;

for(int i = 0; i < n; i++) {
cin>>arr[i];
}

long x = arr, a;

for(int i = 1; i < n; i++) {
a = arr[i];
arr[i] ^= x;
x = a;
}
``````

// for(auto x: arr) cout<<x;

``````	for(int i = 0; i < n; i++) {
if((arr[i] >> (k - 1)) & 1)
ele++;
}

cout<<ele;
``````

}

can someone point out where i have done mistake

#include <bits/stdc++.h>
#define ll long long int
using namespace std;
ll kth(ll n, ll k)
{
if ((n >> (k - 1)) & 1)
return 1;
else
return 0;
}
int main() {

``````    ll n,k;
cin>>n>>k;
ll a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
ll c=0;
for(int i=1;i<n;i++)
{
ll x=(a[i]^a[i-1]);
// cout<<x<<" ";
if(kth(x,k)==1)
{
c++;

}
}
if(kth(a,k)==1)
c++;
cout<<c;

return 0;
``````

}

Just use `1LL<<k` instead of `1<<k`

2 Likes

Creating Local array gives Wrong ans declare
global array with size greater than1000000
but it should be slightly greater
then try

This Worked for me

Create global array and then try

1 Like

Oh this is the great problem
How I wish if somebody could explain why this happened.
In case you do not understand the solution,
I took all inputs first, in a list
Then I assigned n as the first element of my list.
Then I checked if size of list=n+2, because that’s what the problem says right?
Oh, now how will I check that? I decided to run an infinite loop, in case size \neq n+2
And what do I find? My code TLEd

So, after countless wrong constraints, wrong inputs, now we have no inputs.
PS- this is what I did to get AC: in case I found this gibberish, I increment ans by 1, and behold, I have the green tick.

Update/Edit : All problems are moved to practice section, you can submit your solutions now

CodeChef take some time to move contest problems, to practice section. So once the problems are moved to practice section you can submit the solutions to it. It may take some more time as this is the task that codechef will do @admin @nehak_21 plz look into it.

Hope you liked this contest and are waiting for our next month’s contest no we didn’t

Yes questions were good

Thanks for your great support man Do suggest the improvements for us so that we can improve upon it, and can do better from next time The ones getting wrong answers using array make ur array global
u will get AC

Below given solution worked for me, but I wonder why this happened, Please let me know what is the reason local array doesn’t work, also 1LL is required as someone pointed out, isn’t 1 supposed to typecast to LL by default

``````bool CheckKthBit(ll a,ll k){
return (a&(1LL<<(k-1)));
}

ll const HelpBob_N = 1000005;
ll Help_bob_array[HelpBob_N];

void HelpBob(){
int n,k;
cin>>n>>k;
for(int i =0;i<n;i++){
cin>>Help_bob_array[i];
}
ll ans = CheckKthBit(Help_bob_array,k);
for(int i=1;i<n;i++){
if(CheckKthBit((Help_bob_array[i]^Help_bob_array[i-1]),k)) ans+=1;
}
cout<<ans;
}``````

No, in C, Integer Constants are implicitly interpreted as int. If you want to make it interpret as Long or Long Long, you must include the suffix L or LL. Here’s the link where you can get detailed info about Integer Constants.