Answers to: bitwise operationhttps://discuss.codechef.com/questions/111644/bitwise-operation<p>i dont understand why 1 one is faster than 2 :-<br><br></p>
<h2>1:-<br></h2>
<p>for j in array:<br> number+=(1<<(k-j)) <br></p>
<h2>2:-<br></h2>
<p>for j in array:<br> number+=(1<<(j)) <br></p>
<p>link to the problem <a href="https://www.codechef.com/problems/UNIONSET">here</a><br></p>
<p>first solution link <a href="https://www.codechef.com/viewsolution/15431811">here</a><br><br>
second solution link <a href="https://www.codechef.com/viewsolution/15431808">here</a><br></p>enSat, 16 Sep 2017 17:27:42 +0530Comment by meooow on phantomhive's questionhttps://discuss.codechef.com/questions/111644/bitwise-operation#111747<p>Yes that might be it. I tried to test this locally using Python, and for the worst case of T=10, N=K=2500, and each set={K}, the solutions took 9.39 and 11.7 seconds. But clearly if the test data had such a case neither solution would pass at all (assuming my system is at least as fast as the judge). So I reduced the difficulty of test cases and got something like 4.49 and 5.79 seconds which is close to the result on submission. So you're probably right.</p>meooowSat, 16 Sep 2017 17:27:42 +0530https://discuss.codechef.com/questions/111644/bitwise-operation#111747Comment by phantomhive on phantomhive's questionhttps://discuss.codechef.com/questions/111644/bitwise-operation#111727<p>i think it about the input.. the input data must have more big number which when done this "number+=1«number" and when we or it larer takes much time as the number is too large but when we do this "1«(k-number)" where "k>=number" we make sure that we set bit from right not from left that results in a small number but it only works if we have more big numbers and less small numbers!</p>phantomhiveSat, 16 Sep 2017 14:40:50 +0530https://discuss.codechef.com/questions/111644/bitwise-operation#111727Comment by meooow on phantomhive's questionhttps://discuss.codechef.com/questions/111644/bitwise-operation#111716<p><a href="/users/158252/phantomhive"><a href="/users/158252/phantomhive">@phantomhive</a></a> the first difference is that the first one is compiled in PyPy and the other in Python. However even when both are compiled on PyPy or Python there is significant difference (> 3s) between the execution times. I tried a few variations to understand what's going on but sadly I don't. </p>
<p>If anyone else can figure it out, please do, this is very curious :D</p>meooowSat, 16 Sep 2017 13:46:56 +0530https://discuss.codechef.com/questions/111644/bitwise-operation#111716