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:
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…
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
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
@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;
}