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 | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
# | User | Contrib. |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
2 | maomao90 | 163 |
4 | atcoder_official | 161 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | nor | 153 |
9 | 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.