| 2025 ICPC Asia Taichung Regional Contest (Unrated, Online Mirror, ICPC Rules, Preferably Teams) |
|---|
| Finished |
Kenny is a kindergarten teacher who is teaching his students about math. To help them learn, he wants to give them homework in an enjoyable and non-annoying format – Number Search.
A Number Search puzzle is similar to a Word Search puzzle, but instead of words, it's about finding math expressions. An instance of the puzzle consists of two parts: a grid with $$$n$$$ rows and $$$m$$$ columns, and a list $$$a_1, a_2, \dots, a_q$$$ of $$$q$$$ target numbers to search for. Each cell in the grid contains a digit from 1 to 9, a plus sign +, or a multiplication sign *.
An expression can be formed by joining one or more consecutive characters along the same row, column, or diagonal, in a straight line (in either direction). Each expression can be defined by its starting cell and ending cell. Two expressions are considered different if they start or end at different cells, even if they contain the exact same characters.
A valid expression must be of the form $$$$$$ num \quad op \quad num \quad op \ \dots \ op \quad num $$$$$$ where each $$$num$$$ is a sequence of one or more digits, and each $$$op$$$ is either + or *. For example, "123" and "1+2*3+45" are valid expressions, while "+123" and "2**5" are not. The value of an expression is the result of evaluating it following typical arithmetic rules.
The goal of the puzzle is to count, for each number $$$a_i$$$, how many different valid expressions in the grid evaluate to $$$a_i$$$.
To demonstrate the rules, consider the following completed Number Search puzzle:
Let's denote the cell at row $$$r$$$ and column $$$c$$$ as $$$(r,c)$$$.
Kenny can't wait to see children enjoy solving interesting Number Search puzzles. But before giving them a puzzle, he needs to have the answers ready. Please help him calculate the answers for each puzzle he has prepared.
The first line contains three integers $$$n$$$, $$$m$$$, and $$$q$$$, representing the number of rows, the number of columns, and the number of target numbers, respectively.
Each of the following $$$n$$$ lines contains a string of $$$m$$$ characters, representing the grid.
The $$$i$$$-th of the following $$$q$$$ lines contains an integer $$$a_i$$$, representing the $$$i$$$-th target number.
Print $$$q$$$ lines. The $$$i$$$-th line contains an integer, representing the answer for $$$a_i$$$.
9 8 4 4216793+ 717*4*54 7+5+727* 45149+71 8+26697* +189*2+9 5+*244+7 42595952 97+*315+ 67 420 3 727
2 0 4 3
| Name |
|---|


