Can anyone tell me how to solve this problem i don't understand their editorial. https://atcoder.jp/contests/abc164/tasks/abc164_d
# | User | Rating |
---|---|---|
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 |
# | User | Contrib. |
---|---|---|
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 |
Can anyone tell me how to solve this problem i don't understand their editorial. https://atcoder.jp/contests/abc164/tasks/abc164_d
Name |
---|
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.