#C9833. Farm Rotation and Crops Query
Farm Rotation and Crops Query
Farm Rotation and Crops Query
You are given a farm represented by a grid of size n x m, where each cell contains either a 0 (empty field) or a 1 (crop). You are also given q queries. Each query provides an integer k that represents the number of times the grid should be rotated 90° clockwise. After rotating the grid, your task is to determine the maximum number of continuous crops (i.e. consecutive ones) in any row of the rotated grid.
The rotation operation is defined by the formula: $$\text{NewCell}(i,j)=\text{OldCell}(n-1-j,i)$$. Note that since rotating 4 times results in the original farm, you only need to consider \(k \bmod 4\) rotations.
For each query, output the maximum continuous sequence of 1s among all rows of the grid after rotating.
inputFormat
The input is given from stdin and has the following format:
- The first line contains three integers separated by spaces: n m q, where \(1 \le n, m \le 10^3\) (for example) and q is the number of queries.
- The next n lines each contain m integers (0 or 1), representing the farm grid.
- The last line contains q integers, each the value of k for a query.
All input is read from stdin.
outputFormat
For each query, print the maximum number of consecutive 1s in any row after rotating the grid by \(k \bmod 4\) times. The answers for the q queries should be output on a single line separated by a space, written to stdout.
## sample3 4 2
0 1 0 1
1 1 1 0
0 0 1 1
1 2
2 3