# Help needed in XORSUB

This might be very naive, but still, can anyone help me by telling why the problem XORSUB can’t be solved with an intuitive subset selection recursive method like:

ll recurse(ll x, ll cur) {
if(x >= n) return cur;
return max(recurse(x+1, cur), recurse(x+1, cur^a[x]));
}

I know this problem will be solved with gaussian elem. but I can’t get it.
Thanks for anyhelp.

Are you asking about why will this solution get TLE ?
Then answer is your solution is O(2^n) (as you are checking each and every subset naively and there are total 2^n subsets possible of a set having size n)
and 2^{100} == 10^{30} whereas one can only do about 10^8 to 5*10^8 operations in one second…

2 Likes

No i knew recursion is a tle but i was getting a WA on the above code, even on the smaller subtasks of the problem, although I have found the mistake I was doing in the implementation part.
BTW, can u suggest some good resources for gaussian elimin.??

@shan01
I don’t think we need anything like that for solving this question… I have a very simple solution…
https://www.codechef.com/viewsolution/24082100
see this solution and try to understand what I did…
It has very very simple solution trust me…
Ping me if you still don’t understand it…
boolean array a stores if it exist a subset having value of xor=index

4 Likes

Thanks man, I think that was the easiest to understand among all the solutions I encountered.
cheers!

2 Likes

Welcome
Like my answer then

3 Likes

i tried to solve this question using normal array - got RE ( as size is getting too large).
then uses index of boolean array max size will be 1024 ( worked fine)
then i tried unordered set getting WA for half of test case - unordered_set solution

1 Like

I thought a written acknowledgement would be much more valuable.

3 Likes

Yeah it was valuable… Thanks…
I want to increase my trust level

2 Likes

@l_returns has an awesome and easy to understand solution.
But if you are looking for a recursive solution then you can have a look at this solution.

3 Likes

@shivamchef
unordered set means it completely unordered… adding one element can change order of all other elements…
So if you insert elements while you are using for each loop then there will be lot of mess…
https://www.codechef.com/viewsolution/24082696
here is your AC solution
check this code and you’ll understand the problem…

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

#define ll long long int
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007

int main() {
FIO;
int t,n,k,i,j;
unordered_set<int> v;

v.insert(0);
v.insert(5);
v.insert(8);

for(auto it:v)
cout << it << " ";
cout << endl;

v.insert(4);

for(auto it:v)
cout << it << " ";
cout << endl;

v.insert(10);

for(auto it:v)
cout << it << " ";
cout << endl;

return 0;
}
``````
1 Like

Karma Farming

2 Likes

yeah inspired by @vijju123 XD…

2 Likes

Do you know anyone whose trust level increased? If yes, then how much karma he farmed?

1 Like

I think there are 3 levels and vijju is on 3rd one… I am on 2nd one… XD
Now i think i wont get to 3rd level…

2 Likes

That’s permanent level dude
I don’t think any change is possible
Until and unless @vijju123 (pseudo @admin) declares that after so and so karma farming he will increase the level.

Extra bump - @taran_adm @taran_1407 (Possessing two accounts is not allowed.)

1 Like

exactly… got it XD… never mind…
that’s very bad @taran_1407@vijju123 may ban both of them… be careful XD…

1 Like

Off-topic level --> infinity

2 Likes

You just pitched an idea for @vijju123 .
@taran_1407 beware!

thanks for the solution