Universal Cup Judging System

Universal Cup

実行時間制限: 2.0 s メモリ制限: 1024 MB 満点: 100
統計

给定一个长度为 $N + M$ 的字符串 $S$,其中包含 $N$ 个字符 + 和 $M$ 个字符 -,以及一个包含 $M$ 个整数的集合 $A = \{A_1, A_2, \dots, A_M\}$。

准备两个集合 $X = \{\}$ 和 $Y = \{\}$,并按顺序对 $i = 1, 2, \dots, N+M$ 执行以下操作:

  • 当 $S$ 的第 $i$ 个字符为 + 时,从 $1$ 到 $N$ 中选择一个尚未包含在 $X$ 或 $Y$ 中的整数,并将其加入 $X$。
  • 当 $S$ 的第 $i$ 个字符为 - 时,从 $X$ 中移除最小的整数 $m$,并将其加入 $Y$。根据约束条件,保证在执行此操作前 $X$ 不为空。

确定加入 $X$ 的整数顺序共有 $N!$ 种方式。在这些方式中,求出使得所有操作完成后 $Y = A$ 的方案数。请输出答案对 $998244353$ 取模的结果。

输入格式

输入通过标准输入按以下格式给出:

$N \ M$ $S$ $A_1 \ A_2 \ \dots \ A_M$

  • 所有输入数字均为整数。
  • $1 \le M \le N \le 300$
  • $S$ 是一个长度为 $N + M$ 的字符串,由 $N$ 个 + 和 $M$ 个 - 组成。
  • 对于 $i = 1, 2, \dots, N + M$,前 $i$ 个字符中 - 的数量不超过前 $i$ 个字符中 + 的数量。
  • $1 \le A_1 < A_2 < \dots < A_M \le N$

输出格式

在一行中输出答案。

样例

输入 1

4 2
++-++-
1 3

输出 1

4

输入 2

6 4
++-++---++
2 3 4 6

输出 2

48

输入 3

20 10
++++-++++++--+--+-+++++--+-++-
1 2 3 4 5 6 7 9 12 13

输出 3

179396825

说明

对于第一个样例,作为满足条件的操作序列示例,可以考虑以下过程:

  • 当 $i = 1$ 时,将 $3$ 加入 $X$。此时 $X = \{3\}$,$Y = \{\}$。
  • 当 $i = 2$ 时,将 $4$ 加入 $X$。此时 $X = \{3, 4\}$,$Y = \{\}$。
  • 当 $i = 3$ 时,从 $X$ 中移除最小整数 $3$ 并加入 $Y$。此时 $X = \{4\}$,$Y = \{3\}$。
  • 当 $i = 4$ 时,将 $2$ 加入 $X$。此时 $X = \{2, 4\}$,$Y = \{3\}$。
  • 当 $i = 5$ 时,将 $1$ 加入 $X$。此时 $X = \{1, 2, 4\}$,$Y = \{3\}$。
  • 当 $i = 6$ 时,从 $X$ 中移除最小整数 $1$ 并加入 $Y$。此时 $X = \{2, 4\}$,$Y = \{1, 3\}$。

对于第二个样例,$S$ 的结尾不一定是 -

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.