Блог пользователя avijha_98

Автор avijha_98, история, 4 года назад, По-английски

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

  • Проголосовать: нравится
  • +1
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +2 Проголосовать: не нравится

check this

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +1 Проголосовать: не нравится

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 !