B — Almost Ternary Matrix
Author: Gheal
Solution
The general construction consists of a $$$2 \times 2$$$ checkerboard with a $$$1$$$-thick border. Here is the intended solution for $$$n=6$$$ and $$$m=8$$$:
https://codeforces.me/predownloaded/75/c4/75c46e19cc3cf6f890139b0e74774c3a6fc387db.png
Time complexity per testcase: $$$O(nm)$$$.