#P9743. 「KDOI-06-J」旅行
「KDOI-06-J」旅行
Problem Description
Little C is traveling in Country C.
Country C has cities, which can be viewed as an grid. Define as the city in the -th row and the -th column of the grid.
There are transportation systems in this country:
- For all , there is a one-way railway built by Company L from to .
- For all , there is a one-way railway built by Company Z from to .
In each city, there is a ticket office. At the ticket office in city , you can buy one railway ticket of Company L for yuan, and buy one railway ticket of Company Z for yuan. When you have one railway ticket of a company, you can take any railway segment of that company and consume that ticket. Note that one railway ticket can be used once and only once.
Little C initially is in city . He wants to travel in Country C, but he does not want to waste any money (that is, when his trip ends, he should not have any extra unused tickets in hand). For all , find the number of ways for him to spend yuan and end the trip at city , modulo .
Two travel plans are different if and only if the cities Little C passes through are different, or the numbers of railway tickets of some company that he buys in some city are different.
Input Format
Read data from standard input.
The first line contains three positive integers , representing the grid size and the amount of money.
The next lines each contain positive integers; the -th integer in the -th line represents .
The next lines each contain positive integers; the -th integer in the -th line represents .
Output Format
Output to standard output.
Output a total of lines, each containing integers, representing the number of ways to end the trip at each point with exactly all the money spent, modulo .
3 3 5
3 2 1
2 1 3
1 3 2
1 2 3
2 3 1
3 1 2
0 0 0
0 1 5
1 3 5
Hint
[Sample Explanation #1]
The plans to reach are:
- Buy Company L railway ticket at ; take Company L's railway to ; buy Company L railway ticket at ; take Company L's railway to .
The plans to reach are:
- Buy Company L railway ticket at ; take Company L's railway to ; buy Company Z railway ticket at ; take Company Z's railway to .
The plans to reach are:
- Buy Company Z railway ticket at ; take Company Z's railway to ; buy Company L railway tickets at ; take Company L's railway to ; take Company L's railway to .
- Buy Company L railway ticket and Company Z railway ticket at ; take Company Z's railway to ; take Company L's railway to ; buy Company L railway ticket at ; take Company L's railway to .
- Buy Company L railway ticket and Company Z railway ticket at ; take Company L's railway to ; take Company Z's railway to ; buy Company L railway ticket at ; take Company L's railway to .
The plans to reach are:
- Buy Company L railway ticket and Company Z railway tickets at . After that, there are ways to take railways of the two companies from to .
- Buy Company Z railway ticket at ; take Company Z's railway to ; buy Company L railway ticket and Company Z railway ticket at . After that, there are ways to take railways of the two companies from to .
[Sample #2]
See travel/travel2.in and travel/travel2.ans in the contestant directory. This sample satisfies the constraints of test points .
[Sample #3]
See travel/travel3.in and travel/travel3.ans in the contestant directory. This sample satisfies the constraints of test point .
[Constraints]
For all data, it is guaranteed that: , .
| Test Point ID | ||||
|---|---|---|---|---|
Translated by ChatGPT 5