avijha_98's blog

By avijha_98, history, 4 years ago, In English

Can anyone tell me how to solve this problem i don't understand their editorial. https://atcoder.jp/contests/abc164/tasks/abc164_d

  • Vote: I like it
  • +1
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +2 Vote: I do not like it

check this

»
4 years ago, # |
Rev. 3   Vote: I like it +1 Vote: I do not like it

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 !