### Woburn Challenge 2018-19 Round 1 - Senior Division

## Problem 1: Inspiration

It's time for a history test! Unfortunately, while some students have come well-prepared, others appear to have forgotten about the test entirely. They may need some "inspiration" to get through it with passing grades.

The desks in H.S. High School's history classroom are laid out in a nice, traditional grid. The grid has `R` (1 ≤ `R` ≤ 50,000) rows, numbered 1..`R` from front to back, and `C` (1 ≤ `C` ≤ 10) columns, numbered 1..`C` from left to right. The state of each desk in a given row `r` and column `c` is described by an integer `D _{r, c}` (0 ≤

`D`≤ 2), which is one of the following:

_{r, c}- 0: That desk is unoccupied
- 1: That desk is occupied by a "type-1" student — one who has studied for the test
- 2: That desk is occupied by a "type-2" student — one who has
*not*studied for the test

Each type-2 student is in trouble… unless they can catch a glimpse of inspiration, in the form of a type-1 student's test paper. Without looking too suspicious, a student can see manage to see the papers on some desks directly in front of them, in the same column. However, they can only clearly see at most the closest `K` (1 ≤ `K` ≤ `R` − 1) desks in front of them. In other words, the test paper of a type-1 student sitting in row `r`_{1} and column `c`_{1} can be seen by a type-2 student sitting in row `r`_{2} and column `c`_{2} if and only if `c`_{1} = `c`_{2} and `r`_{2} − `K` ≤ `r`_{1} ≤ `r`_{2} − 1. Note that a type-2 student doesn't gain any additional benefit from seeing multiple type-1 students' papers, and that it's possible for a single type-1 student's paper to inspire multiple type-2 students.

How many of the type-2 students can be inspired by looking at at least one type-1 student's test paper?

### Subtasks

In test cases worth 4/13 of the points, `K` ≤ 10.

In test cases worth another 5/13 of the points, `K` = `R` − 1.

### Input Format

The first line of input consists of three space-separated integers, `R`, `C`, and `K`.

`R` lines follow, the `i`-th of which consists of integers, `D`_{i, 1..C}, for `i` = 1..`R`.

### Output Format

Output a single integer, the number of type-2 students who can be inspired.

### Sample Input

5 3 2 1 0 1 1 2 2 0 1 2 2 1 2 0 2 2

### Sample Output

4

### Sample Explanation

The type-2 students in the 2nd and 3rd rows of the 3rd column can both be inspired by the type-1 student sitting at the front of that row.

The type-2 student in the 4th row of the 1st column can be inspired by the type-1 student sitting 2 desks in front of them.

Finally, the type-2 student at the back of the 2nd column can be inspired by either of the type-1 students sitting 1 or 2 desks in front of them.

All Submissions

Best Solutions

**Point Value:** 7 (partial)

**Time Limit:** 4.00s

**Memory Limit:** 64M

**Added:** Nov 17, 2018

**Author:** SourSpinach

**Languages Allowed:**

C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

It's quiet in here...