QOJ.ac

QOJ

時間限制: 2 s 記憶體限制: 512 MB 總分: 100

#8164. EX Infix Expression

统计

Alice has recently learned about expressions and now wants to write her own expression calculator.

Rules:

  • Single number: Formed by concatenating several digits (at least one), and must end with a '.' character (excluding quotes). For example, 00123., 0., and 789. are all valid numbers.
  • Single operator: Formed by concatenating several digits, followed by a character.
  • Operator character: Represents the operation of the operator. This character must be one of +, *, or ^, representing addition, multiplication, and exponentiation, respectively. Specifically, it is defined that $0^0 = 1$. For example: 000000789+, 123^. If the preceding numerical part is valid, then these are valid operators.
  • Operator number: Represents the priority of the operator. The priority is a positive integer in the range $[1, n]$, where a larger number indicates a higher priority.
  • For operators with the same priority, the problem provides a binary string $C$ of length $n$ to specify whether the operators of that priority are left-associative or right-associative. $0$ represents left-associative, and $1$ represents right-associative. For example, if $C = \text{"111011"}$, the 4th character is '0', meaning operators with priority 4 are left-associative.
  • Left-associative: Means the operator is evaluated from left to right. Example of left-associative: 1.4+2.4^3.4^4. is equivalent to ((1.4+2.)^3.)^4., and its result is the same as ((1 + 2)^3)^4.
  • Right-associative: Means the operator is evaluated from right to left. Example of right-associative: 1.6+2.6^3.6^4. is equivalent to 1.6+(2.6^(3.6^4.)), and its result is the same as 1 + (2^(3^4)).
  • Infix expression:
    1. A single number is a valid infix expression.
    2. If $A$ is a valid infix expression, then $(A)$ is also a valid infix expression.
    3. If $A$ and $B$ are both valid infix expressions, and $c$ is a valid single operator, then $AcB$ is also a valid infix expression.
    4. All other cases are invalid.

Given a binary string $C$ of length $n$ specifying the associativity for each priority level, and an infix expression, determine if the expression is valid. If it is invalid, output "error" (excluding quotes). If it is valid, output the result of the expression modulo $998244353$.

Input

The first line contains a positive integer $n$. The second line contains a binary string $C$ of length $n$. The third line contains a string $S$, representing an infix expression. It is guaranteed that there are no spaces in the expression.

Output

If the infix expression is invalid, output "error". Otherwise, output the result of the expression modulo $998244353$.

Examples

Input 1

2
01
1.2+2.1^3.2*4.2^(5.2*6.)2+7.

Output 1

243640717

Note 1

$243640717 = ((1 + 2)^{(3 * (4^{((5 * 6) + 7)}))}) \pmod{998244353}$

Constraints

Special property 1: The ^ character will not appear. Special property 2: The + and * characters will not appear. Special property 3: The ( and ) characters will not appear.

  • For 8% of the data, $n = 1, 1 \le |S| \le 100$, and special properties 1 and 3 are satisfied.
  • For another 8% of the data, $n = 1, 1 \le |S| \le 100$, and special property 1 is satisfied.
  • For another 20% of the data, $n = 1, 1 \le |S| \le 100$, and special properties 2 and 3 are satisfied.
  • For another 24% of the data, $n = 1, 1 \le |S| \le 1000$, and special property 2 is satisfied.
  • For 100% of the data, $1 \le n \le 9, 1 \le |S| \le 10000$.

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.