Monday, December 16, 2013

SPOJ THINKBIT

Well, I always got "compilation error" or "wrong answer" in THIS.
Here are my solutions that works OK on my local machine but NOT on the SPOJ!
return 2 | !(!(x >> 1)); // I like this one!
// but they don't wanna bit shifts!
return 2 | !(!((x & 2) | (x & 4) | (x & 8) | (x & 16) | (x & 32) | (x & 64) | 
(x & 128) | (x & 256) | (x & 512) | (x & 1024) | (x & 2048) | (x & 4096))); 
// kinda idiotic, but works :)
return 2 | !(!(x & 1073741822)); // OK on 64-bit UNIX
return 2 | !(!(x & 65534)); // 32-bit? here it is...
return 2 | !(!(x & 4094)); // WTF?! this gives "wrong answer" on this f... SPOJ !

Whats wrong with SPOJ guys?

2 comments: