#P7324. [WC2021] 表达式求值
[WC2021] 表达式求值
Description
Define the binary operator <: for two arrays of length (indices from to ), the result of < is also an array of length , denoted by . Then ().
Define the binary operator >: for two arrays of length (indices from to ), the result of > is also an array of length , denoted by . Then ().
Now there are () integer arrays , all of length . You are given an expression to evaluate. Every operand in is one of , and contains only the two operators < and > (they have the same precedence). Therefore, the value of this expression is also an array of length .
In particular, the expression may also contain the operator ?, which means this operator may be < or >. Thus, if the expression contains ? characters, it can generate fully determined expressions, producing results (each result is an array). Your task is to compute the sum of all elements across these result arrays. You only need to output this total sum modulo .
Input Format
The first line contains two integers , representing the array length and the number of arrays.
Lines to each contain integers separated by spaces. The -th number on line represents (, ).
The last line contains a string , representing the expression . contains only the characters 0 to 9, (, ), <, >, ?. A digit character indicates the index of an operand; for example, character 2 means the operand is .
Output Format
Output a single integer: the sum of all elements in the results of the expressions, modulo .
2 3
3 1
2 2
2 3
1>2?0
9
3 3
4 3 2
2 3 1
2 3 3
1?0>2?0
36
5 3
354 321 414 205 257
458 996 554 635 730
681 374 903 966 349
2<0>2<0>(1>2)>(0<0)
4276
见附件中的 expr/expr4.in
见附件中的 expr/expr4.ans
Hint
Sample Explanation #1
The expressions generated by are:
><, whose result is .>>, whose result is .
So the answer is .
Constraints
For all test points: , , , .
The specific limits for each test point are shown in the table below:
| Test Point ID | Special Restrictions | ||
|---|---|---|---|
| does not contain parentheses or question marks | |||
| does not contain question marks | |||
| does not contain parentheses | |||
| None | |||
| does not contain question marks | |||
| None | |||
Translated by ChatGPT 5
京公网安备 11011102002149号