Hello Everyone !!
Can Someone explain me why this solution gave TLE Verdict ??
# | User | Rating |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 166 |
2 | maomao90 | 163 |
2 | Um_nik | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | Dominater069 | 153 |
Hello Everyone !!
Can Someone explain me why this solution gave TLE Verdict ??
Name |
---|
TLE is time limit exceeded. Which simply means make your code more efficient.
I agree, But I wanted to know which part in my code is causing such inefficiency!!
I think (a[j]<<1) part it is not required actually u can simply check __gcd(a[i],2*a[j])> 1 || __gcd(2*a[i],a[j])>1 then count++
Yes, you are right That works But (a[j]<<1) is equal to a[j]*2 and is faster, That should not cause TLE Right??
Maybe it's yours overloaded sort, try this, maybe it'll help: Also yours output is empty maybe infinite loop
when sorting if compare function have 2 odd or 2 even numbers it's output will give different
Your comparator is wrong, it has to implement strict weak ordering, which essentially means that comparator should return
true
if you for sure want first element before second andfalse
in any other case (including if you don't care about order)The correct comparator would be
Thanks a Ton Maksim1744, Learnt a new thing today :)
You can just use
return a % 2 < b % 2;
(https://mirror.codeforces.com/contest/1535/submission/118369895)Just like how the shortest solution sorts with
key = lambda x: x%2
.All you should know about comparator in C++
Thank You smit.mangukiya
Your comparator function is wrong .... You may have simply used greater()
Thank you h1teshtr1path1