Hello Everyone !!
Can Someone explain me why this solution gave TLE Verdict ??
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3831 |
3 | Radewoosh | 3646 |
4 | jqdai0815 | 3620 |
4 | Benq | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | gamegame | 3386 |
10 | ksun48 | 3373 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 164 |
1 | maomao90 | 164 |
3 | Um_nik | 163 |
4 | atcoder_official | 160 |
5 | -is-this-fft- | 158 |
6 | awoo | 157 |
7 | adamant | 156 |
8 | TheScrasse | 154 |
8 | nor | 154 |
10 | Dominater069 | 153 |
Hello Everyone !!
Can Someone explain me why this solution gave TLE Verdict ??
Название |
---|
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://codeforces.net/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