Can anyone tell me how to solve this problem i don't understand their editorial. https://atcoder.jp/contests/abc164/tasks/abc164_d
№ | Пользователь | Рейтинг |
---|---|---|
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 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Can anyone tell me how to solve this problem i don't understand their editorial. https://atcoder.jp/contests/abc164/tasks/abc164_d
Название |
---|
check this
Take some $$$[i, j]$$$ and let $$$d = j - i$$$. The number which is formed is this one: $$$D = 10^d * S_i + 10^{d-1} * S_{i+1} + \dotsc + S_j$$$
Now let us suppose that we iterate the array in reverse order. When we are at position $$$i$$$ the current number that we have is: $$$A = 10^i * S_i + 10^{i-1} * S_{i-1} + \dotsc + S_n$$$ assuming that $$$i$$$ now runs from $$$0$$$ to $$$N-1$$$ in reverse order. When we were at position $$$j - 1$$$ the corresponding number which was formed was: $$$B = 10^{j-1} * S_{j-1} + 10^{j-2} * S_{j-2} + \dotsc + S_n$$$.
Now what is the number which is formed by $$$C = A - B$$$ ? It has the same coefficients $$$S_i$$$ with $$$D$$$, but $$$C$$$ has larger exponents on the corresponding $$$10^x$$$. With some observations you can see that this is not a problem. $$$C$$$ is divided by $$$2019$$$ if and only if $$$D$$$ is divided by $$$2019$$$.
This means that we just need to check if $$$A - B$$$ is divided by $$$2019$$$ which is equivalent with checking if $$$A == B \; (mod \; 2019)$$$. Therefore, using a count[] we can solve the problem !
Thank You.