Evaluation
Time limit2sMemory limit512 MB
Evaluate an expression drawn as 2D ASCII art modulo 10^9+7, where the art encodes numbers, parentheses, fourth roots, operators, and fractions.
- Level
Hard8 of 10
- Topics
- Implementation, Recursion, Number theory
- Solved
- No attempts yet
Problem
Two pictures are defined first.
- is a picture of width and height made only of spaces.
- is a picture of width 1 and height made only of
|characters.
An expression is one of the following five forms.
- Number. has the form below, and . It is given that . Here , and has width and height .
- Parentheses. .
If the height of is 1, has the form below, with width and height 1.
If the height of is , has the form below, with width and height .
| / | E' (width ) | \ |
| | | |
| \ | | / |
- Root. has the form below, and . has width and height .
- Operation. has the form below, where op is one of
+,-,*,/. . Here . has width and height .
- Fraction. has the form below, and . has width and height .
The input is given so that no expression has more than one parse tree under these rules. In all of the above, is prime.
Input
The first line has the number of rows and the number of columns . Each of the next lines has characters, and together they give the expression . The width of is and its height is .
Output
Print eval().