Hello Everyone !!
Can Someone explain me why this solution gave TLE Verdict ??
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
2 | atcoder_official | 162 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | nor | 150 |
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