puupil's blog

By puupil, history, 5 hours ago, In English

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.

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

»
5 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

Awesome

»
4 hours ago, # |
  Vote: I like it +11 Vote: I do not like it

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 hours ago, # |
  Vote: I like it +6 Vote: I do not like it

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

  • »
    »
    3 hours ago, # ^ |
    Rev. 2   Vote: I like it +10 Vote: I do not like it

    Actually in Unix you can control file access permissions with same idea:

    1 + 2 + 4 = 7

    So it's not lazy it is common practice.

»
2 hours ago, # |
  Vote: I like it +3 Vote: I do not like it

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.

  • »
    »
    117 minutes ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    My Implementation of the same: 278562557

  • »
    »
    95 minutes ago, # ^ |
      Vote: I like it +1 Vote: I do not like it

    does prefix function considers overlaps?

    • »
      »
      »
      84 minutes ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      yes, say our string is $$$aaaaa$$$ then $$$pi_n$$$ would be $$$4$$$ since the suffix of length $$$4$$$ equals the prefix of length $$$4$$$

      • »
        »
        »
        »
        70 minutes ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        OH! didn't know that. thanks!