Explanation
We generate a larger grid repeating each character from the small grid both horizontally and vertically, so that every character becomes a block of identical characters in the final output.
To do this, we can first repeat each of the characters per row consecutive times, and repeat each of these expanded rows in the grid consecutive times as well.
Video Solution
By Jeffrey Meng
Video Solution Code
Implementation
Time Complexity:
with open("cowsignal.in") as read:height, width, scale = map(int, read.readline().split())signal = [read.readline() for _ in range(height)]with open("cowsignal.out", "w") as written:for i in range(scale * height):for j in range(scale * width):print(signal[i // scale][j // scale], end="", file=written)print(file=written)
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!