## Wesley's Anger Contest 5 Problem 5 - A Squirrel's Life

View as PDF

Points: 25 (partial)
Time limit: 3.0s
Memory limit: 256M

Author:
Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

The life of a squirrel is a mysterious one. A typical squirrel experiences exactly events in their lifetime. Recently, scientists have discovered that there are different types of events and have categorized them from to . Each event can lead directly to several different types of events. For example, hunting for acorns could potentially lead to getting chased by a dog.

Unfortunately, not every squirrel will live a happy life. Scientists have devised the following conditions which determine the happiness of a squirrel:

• A squirrel must find at least one good shelter, which scientists have defined as an event of type .
• A squirrel must find at least one partner, which is defined as an event of type .
• A squirrel must have access to exactly supplies of acorns. Scientists have defined the event of finding supply of acorns as an event of type . This means that a squirrel must encounter an event of type exactly times in their lifetime to become happy.

The squirrel must fulfill all three conditions in order to live a happy life, and the order in which the conditions are satisfied does not matter. The life of a squirrel always starts with its birth and ends with its death. These events are described as type and respectively.

Using the required conditions for a happy squirrel life, how many distinct ways can a squirrel end up living a happy life? Two lives are considered to be different if there is at least one event in the events where there are two different types of events happening at a specific moment (all events have the same duration). Since the answer could get very large, output the answer modulo .

#### Constraints

For this problem, you will NOT be required to pass all the samples in order to receive points. In addition, you must pass all previous subtasks to earn points for a specific subtask.

Only input where no events will lead directly to event type , and no events are directly led from event type is allowed.

#### Input Specification

The first line of input contains integers, , , and , representing the number of types of events, the number of events in a lifetime, and the number of supplies a squirrel needs.

The next lines each contain a string of characters. Each character is either 0 or 1. The character on the line describes the link from the to the event type. A 0 indicates that the event type will never lead to the event type, and a 1 indicates that the event type can directly lead to the event type.

#### Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output, on a single line, the total number of distinct ways a squirrel can live a happy life, modulo .

#### Sample Input 1

5 5 0
01100
00110
01011
00001
00000

#### Sample Output 1

1

#### Sample Explanation 1

There is only one way where a squirrel can live a happy life:

• The squirrel is born (event type ), finds a partner (event type ), finds a shelter (event type ), finds another partner (event type ), and finally dies (event type ).

Note that any squirrels that find a supply of acorn will never live a happy life.

#### Sample Input 2

5 7 2
01000
00110
01011
00101
00000

#### Sample Output 2

3

#### Sample Explanation 2

There are three possible ways a squirrel can live a happy life:

• The squirrel is born (event type ), finds a shelter (event type ), finds a partner (event type ), finds its first supply of acorn (event type ), finds another partner (event type ), finds its second supply of acorn (event type ), and finally dies (event type ).
• The squirrel is born (event type ), finds a shelter (event type ), finds its first supply of acorn (event type ), finds a partner (event type ), finds another shelter (event type ), finds its second supply of acorn (event type ), and finally dies (event type ).
• The squirrel is born (event type ), finds a shelter (event type ), finds its first supply of acorn (event type ), finds a partner (event type ), finds its second supply of acorn (event type ), finds another partner (event type ), and finally dies (event type ).