Editorial for UTS Open '15 #1 - Caesar Salad


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

Map the i^{th} letter of the alphabet to the number i - 1: A is mapped to 0, B to 1, etc. Then the value of the n^{th} bowl after B button presses is (c_n + B \cdot s_n) \% 26. Simulate all values of B and take the minimum value which produces an acceptable result. Since (c_n + B \cdot s_n) \equiv (c_n + (B + 26) \cdot s_n) \pmod{26}, it is never optimal to have B \ge 26.

Complexity: \mathcal{O}(\sum N)


Comments

There are no comments at the moment.