I've been solving 1311C - Perform the Combo and when i used memset I received TLE 73574138 but when I changed to iterative method I received AC 73575826. This is not the first time happening. What the reason behind this?
# | User | Rating |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 156 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | nor | 152 |
I've been solving 1311C - Perform the Combo and when i used memset I received TLE 73574138 but when I changed to iterative method I received AC 73575826. This is not the first time happening. What the reason behind this?
Name |
---|
Every time you use memset with the third parameter $$$sizeof(a)$$$, it fills the whole array (or matrix) with corresponding values. But because the number of test cases in this problem can be up to $$$10^4$$$, you can fill up $$$10^4 \cdot 2 \cdot 10^5 \cdot 26 = 52 \cdot 10^9$$$ elements in the worst case. Despite the fact that memset is a very fast function, $$$52$$$ billion is a huge number of operations. But when you fill up all values iteratively, you can be sure that you will do this at most $$$\sum n \cdot 26$$$ times (i.e. $$$2 \cdot 10^5 \cdot 26 = 5.2 \cdot 10^6$$$ times.
Thank you, didn't think of that