AtCoder Regular Contest 211 (Div. 2)
C
Forest
AtCoder
⌀ 1792
原题
← BD →
翻译中…

Problem Statement

翻译中…

You are given a positive integer $N$, a string $S$ of length $N$ consisting of # and ., and a length-$N$ sequence of positive integers $R=(R_1,R_2,\dots,R_N)$.

翻译中…

There is a forest with $N$ sections arranged in a single horizontal line. The sections are numbered $1,2,\dots,N$ from left to right.

翻译中…

Some sections have trees. Specifically, section $i$ has a tree if and only if the $i$-th character of $S$ is #. It is guaranteed that the following operation can be performed at least once.

翻译中…

You can repeat the following operation as many times as you like:

翻译中…
  • Choose two sections without trees. Let sections $i$ and $j$ (where $i < j$) be the chosen sections from left to right. Then, all trees between sections $i$ and $j$ are removed, and you gain a reward of $R_i+R_j$.
翻译中…

Here, you cannot perform an operation that removes no trees.

翻译中…

Find the number of ways to perform the first operation to achieve the maximum possible total reward. Two ways are considered distinct if and only if there exists a section chosen in one way but not in the other.

翻译中…

Constraints

翻译中…
  • $3\leq N\leq 2\times 10^5$
  • The length of $S$ is $N$, and each character is # or ..
  • $1\leq R_i\leq 10^9$ $(1\leq i\leq N)$
  • The operation can be performed at least once.
  • $N$ and $R_i$ are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

N
S
R_1 R_2 \dots R_N

翻译中…

Output

翻译中…

Output the answer.

翻译中…

样例

Input #1
8
...###..
20 25 1 1 30 2 1 1
Output #1
2
There are six ways to perform the first operation, as follows: - Choose sections $1$ and $7$. The trees at sections $4,5,6$ are removed, and you gain a reward of $21$. - Choose sections $1$ and $8$. The trees at sections $4,5,6$ are removed, and you gain a reward of $21$. - Choose sections $2$ and $7$. The trees at sections $4,5,6$ are removed, and you gain a reward of $26$. - Choose sections $2$ and $8$. The trees at sections $4,5,6$ are removed, and you gain a reward of $26$. - Choose sections $3$ and $7$. The trees at sections $4,5,6$ are removed, and you gain a reward of $2$. - Choose sections $3$ and $8$. The trees at sections $4,5,6$ are removed, and you gain a reward of $2$. No matter which operation is performed, all trees are removed, so a second operation cannot be performed. The maximum possible total reward is $26$.
Input #2
5
.#.#.
211 182 192 182 211
Output #2
2
The maximum possible total reward is $825$. Note that the goal is not to maximize the reward obtained in the first operation. If you choose sections $1$ and $5$ first, you can gain a reward of $422$, but no operation can be performed afterwards, and the total reward cannot reach $825$.
Input #3
11
#..#.##.#..
192 192 192 211 182 192 182 192 182 211 182
Output #3
3
题目信息
题号
arc211_c
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。