UNIONSET - A Simple Approach

crux of the solution is same, thanks anyways !

Yea I was surprised too that this can be accepted in o(kn2), infact o(kn2) doesn’t work if you don’t take set length into consideration. :stuck_out_tongue:

I see that you are maintaining a max variable throughout check whether it equals k, nice one mate !

I’m confused for that too, it’s just that i was trying many solutions and this was what worked for me.

1 Like

Probably O(k*N^2)

Thanks for the suggestion, I’ll make the adjustments, new to posting solutions so bear a bit. :slight_smile:

To solve the general case, you need something like deepak_13’s solution, by representing each set as bits and performing efficient bitwise OR to achieve O(N^2\frac{K}{32}) time.

Yea i followed that, looked more effecient, that’s why i asked for suggestions to know a better solution than mine.

Update:
the solution only works since k<=sum of lengths of all sets.

Awesome solution man :slight_smile:

Amazing solution~

My second method seems to be wrongly implemented. Please ignore it.

The approach that works in c++ will definitely work in java. Having said that, I think addition to bitset is costly and thus exceeding time.

No problem mate :slight_smile:

Be mindful of using Java Scanner, gives a lot of overhead when reading large input. Try using BufferedReader or similar.

Try a faster input method for all competitive questions as we need to be cautious of not exceeding the time constraints.

Right, inbuilt STL functions suffices too ^^

Right, thanks for pointing that ^^

I am trying to code a O(n^2*k) C/C++ solution using scanf for reading inputs. Still it is passing the small test cases, and TLE for large inputs. Please help me find where the performance issue is. Here is the link to latest solution CodeChef: Practical coding for everyone

Redirect your question here- "I want to ask a question" - Ask them all here! - meta - CodeChef Discuss

Asking for upvotes is against rules.

1 Like