Salt and Pepper (Small)
Time limit1sMemory limit512 MB
Given an M by N brightness matrix and odd window size W, output the median of every W by W window.
- Level
Easy3 of 10
- Topics
- Array, Sorting, Brute force
- Solved
- No attempts yet
Problem
Gap and Eul are a couple. One evening they went to a restaurant for cream cheese spaghetti. The plate looked good, so Gap took a photo with a phone, and while getting ready to post it on social media Gap noticed the salt and pepper scattered over the spaghetti.
Gap did not like the salt and pepper in the photo and asked Eul to remove them. Eul answered that this was easy, pulled paper and a pen out of a bag, and wrote the problem down like this.
- An matrix describing the photo is given as input. Each entry is the brightness of one pixel, where 0 is the darkest and is the brightest.
- An integer is also given as input. It defines a matrix as follows.
- where , , .
- is the entry in row and column of matrix , and median is the middle value.
- Compute matrix from matrix and the integer .

How matrix is built from matrix and
Eul opened a laptop and started writing the program, but it did not go well and the spaghetti began to go soft. Write the program for Eul before the spaghetti is ruined.
The median of a set of values is the value that sits in the middle once they are sorted by size. For 1, 2, 3, 3, 100 the median is 3, because 3 is in the middle. is odd, so the number of values in one window, , is odd as well and the median is always a single value.
Input
The first line contains the matrix size and (), the maximum brightness (), and the integer (), separated by spaces. is odd.
Each of the next lines contains integers between 0 and . The th integer on the th of these lines is the entry in row and column of matrix .
Output
Print matrix on lines. Each line holds integers separated by a single space.