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

Автор puupil, история, 5 часов назад, По-английски

A — Alternating Sum of Numbers

Tutorial
Solution

B — Three Brothers

Tutorial
Solution

C1 and C2 — Message Transmission Error(Hard Version)

Hint
Tutorial
Solution

Also if someone has solved C1 and C2 with KMP, please explain your solution.

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

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

Awesome

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

I actually used Z-Algorithm for C1+C2. The core concept of Z made it pretty intuitive: "check if prefix of length $$$x$$$ is equal to suffix of length $$$x$$$" can be rewritten as "check if $$$z_{n-x} = x$$$" in Z.

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

Also for B, I hope I was not the only one being absurdly lazy and typed $$$6 - a - b$$$ as answers.

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

For the kmp solution in C

the prefix function returns an array $$$pi$$$, where $$$pi_i$$$ is the maximum length of a prefix which equals the suffix of the same length in the prefix of size $$$i$$$.

so for a prefix of size $$$n$$$ (the entire string) if $$$pi_n$$$ is less than or equal $$$n / 2$$$ even if the part that will be merged is of minimal length, we still can't use this string to form the given string. However if it's greater than $$$n / 2$$$ then after merging we always get the given string.