Sorry for this noob question, I am new to competitive coding. I want to know what in my code is causing "time limit exceeded". Link to my code
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
Sorry for this noob question, I am new to competitive coding. I want to know what in my code is causing "time limit exceeded". Link to my code
Название |
---|
Let me say, you are asking OS for two arrays of length $$$2000001$$$ in each test case, and you set the arrays' elements equal to 0, which is $$$O(n)$$$, in other words you are doing $$$2000001$$$ iterations for each test case, its just too much. You dont have to clear all the array, you just need to clear first $$$n+1$$$ elements.
Iv'e cleared that and submitted your solution, it works very fast.
I think his code got TLE due to his typo. I mean he intended to declare temp1 and temp2 with size 200001, but somehow he typed 2000001 accidentally and got TLE. I edited his solution 80785027
See the time, the solution runs in about 900ms(it luckily passes), but mine works in about 80ms, indeed you are right but the main problem that caused TLE was that he was doing $$$O(MaxN)$$$ iterations for each test case.
No, it was not a typo. I wanted that big array XD. Thank you for looking into my code!
Oh, I got it! That is why most of the answers declare arrays globally of that size. Thanks for the fast response!
The constraint in the statement is 2e5, yours is 2e6! Edit temp1 and temp2 size to 2e5 then your problem could be solved!