Editorial for COCI '10 Contest 3 #1 Tablica


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.

There are only four different rotations of the given matrix so computing the optimal solution is straightforward - it is necessary to find the maximum of values for all rotations and keep track of the ordinal number of the rotation so we can output it. Keep in mind that if there are several rotations which give the same maximum solution, the smallest number should be output.

If this is the matrix given in the problem statement:

\displaystyle \begin{array}{|c|c|}\hline A & B \\\hline C & D \\\hline\end{array}

By rotating once, twice, and three times we get:

\displaystyle \begin{array}{|c|c|}\hline C & A \\\hline D & B \\\hline\end{array} \Rightarrow \begin{array}{|c|c|}\hline D & C \\\hline B & A \\\hline\end{array} \Rightarrow \begin{array}{|c|c|}\hline B & D \\\hline A & C \\\hline\end{array}

These four matrices generate the following values: \frac A C + \frac B D, \frac C D + \frac A B, \frac D B + \frac C A, \frac B A + \frac D C.

One trick to notice is that by multiplying each of these numbers by A \times B \times C \times D, we simplify double comparisons to integer comparisons.


Comments

There are no comments at the moment.