Editorial for CCC '23 S3 - Palindromic Poster
Submitting an official solution before solving the problem yourself is a bannable offence.
Author:
Subtask 1
For this subtask, since and , we can try and make only the first row and column a palindrome. One way to do this is to fill the first row and column with the letter a
and fill the rest of the grid with the letter b
.
Subtask 2
Because there are so few cases, it suffices to solve this subtask on paper and hardcode the answers. To reduce the amount of casework, notice that if we have a solution for , we can get a solution for by flipping the grid.
Another possible approach is to write a brute force since there are only four important possibilities for each cell.
Subtask 3
This subtask is intended to aid students in thinking about the problem.
Subtask 4
The solutions to subtasks 1 and 2 should give some intuition here. From subtask 1, we propose the following general solution:
Fill the first rows and the first columns with the letter a
and fill the rest of the grid with the letter b
.
We notice that this fails when , , or . We can handle these in pairs since we can flip the grid.
If , we can fill the first columns with the letter a
, and the last column with the letter b
, and then increment the last characters of the last row. For instance, for the input 4 4 0 2
we can output:
aaab
aaab
aaab
aabc
If , every row must be a palindrome. Because of this, starting from a full grid of a
characters, we can easily reduce the number of palindromic columns by two at a time by making matching columns of the first row b
characters. For instance, for the input 4 4 4 2
, we can output:
baab
aaaa
aaaa
aaaa
However, this fails if is not the same parity as , that is, if we cannot get by subtracting an integer number of times from .
In this case, it depends: if is odd, we can use the middle column. For instance, for the input 5 5 5 2
:
babab
aaaaa
aaaaa
aaaaa
aaaaa
However, the input 4 4 4 1
is impossible since there is no middle column.
We can handle and symmetrically by flipping the inputs, processing, and then flipping the output.
Comments