QOJ.ac

QOJ

Time Limit: 3 s Memory Limit: 256 MB Total points: 100

#10959. It's Mooin' Time

Statistics

Note: The time limit for this problem is 3s, 1.5x the default.

Bessie has a string of length $N$ ($1\le N\le 3\cdot 10^5$) consisting solely of the characters M and O. For each position $i$ of the string, there is a cost $c_i$ to change the character at that position to the other character ($1\le c_i\le 10^8$). Bessie thinks the string will look better if it contains more moos of length $L$ ($1\le L\le \min(N, 3)$). A moo of length $L$ is an M followed by $L-1$ Os. For each positive integer $k$ from $1$ to $\lfloor N/L\rfloor$ inclusive, compute the minimum cost to change the string to contain at least $k$ substrings equal to a moo of length $L$.

Input Format

The next line contains Bessie's length-$N$ string, consisting solely of Ms and Os. The next line contains space-separated integers $c_1\dots c_N$.

The next line contains space-separated integers $c_1\dots c_N$.

Output Format

Output $\lfloor N/L\rfloor$ lines, the answer for each $k$ in increasing order.

Sample Data

Sample Input

1 4
MOOO
10 20 30 40

Sample Output

0
20
50
90

Sample Input 2

3 4
OOOO
50 40 30 20

Sample Output 2

40

Sample Input 3

2 20
OOOMOMOOOMOOOMMMOMOO
44743602 39649528 94028117 50811780 97338107 30426846 94909807 22669835 78498782 18004278 16633124 24711234 90542888 88490759 12851185 74589289 54413775 21184626 97688928 10497142

Sample Output 3

0
0
0
0
0
12851185
35521020
60232254
99881782
952304708

Sample Input 4

3 20
OOOMOMOOOMOOOMMMOMOO
44743602 39649528 94028117 50811780 97338107 30426846 94909807 22669835 78498782 18004278 16633124 24711234 90542888 88490759 12851185 74589289 54413775 21184626 97688928 10497142

Sample Output 4

0
0
0
44743602
119332891
207066974

Constraints

  • Input 5: $L=3, N\le 5000$
  • Input 6: $L=1$
  • Inputs 7-10: $L=2$
  • Inputs 11-18: $L=3$
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.