Logo
(追記) (追記ここまで)

34110번 - Conference 서브태스크다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 2048 MB211100.000%

문제

Chairman K is going to host a series of conferences over $N$ days. Each day, exactly one conference is held, and it takes place in one of the three venues: the main venue A or one of the sub-venues B and C.

The venue information for each conference is given as a string $S$ consisting of ‘A’, ‘B’, ‘C’, and ‘?’. For the $i$-th day (1ドル ≤ i ≤ N$), if the $i$-th character of $S$ is ‘A’, the conference is held in venue A. If it is ‘B’, it is held in venue B. If it is ‘C’, it is held in venue C. If it is ‘?’, the venue for the $i$-th day has not been decided yet. However, since the conferences on the first and $N$-th days are expected to have many participants, it has already been determined that venue A will be used on those days.

Chairman K now needs to assign a venue to each undecided conference, choosing one of A, B, or C for each. Additionally, in order to minimize the burden of moving between venues, he wants to minimize the number of indices $j$ (1ドル ≤ j ≤ N - 1$) such that the venue for the $j$-th day differs from the venue for the $(j + 1)$-th day.

There are $Q$ scenarios to consider regarding the assignment of venues. The $k$-th scenario (1ドル ≤ k ≤ Q$) and the corresponding question are as follows:

  • Chairman K has to assign $X_k$ undecided conferences to venue A, $Y_k$ to venue B, and $Z_k$ to venue C. Determine the minimum possible number of indices $j$ such that the venue for the $j$-th day differs from the venue for the $(j + 1)$-th day.

Given the information about the venues and scenarios to consider, write a program to answer the questions.

입력

Read the following data from the standard input.

$N$

$S$

$Q$

$X_1$ $Y_1$ $Z_1$

$X_2$ $Y_2$ $Z_2$

$\vdots$

$X_Q$ $Y_Q$ $Z_Q$

출력

Write $Q$ lines to the standard output. In the $k$-th line (1ドル ≤ k ≤ Q$), output the minimum number of indices $j$ such that the venue for the $j$-th day differs from the venue for the $(j + 1)$-th day, under the condition that Chairman K assigns $X_k$ undecided conferences to venue A, $Y_k$ to venue B, and $Z_k$ to venue C.

제한

  • 2ドル ≤ N ≤ 300,円 000$.
  • $S$ is a string of length $N$ consisting of ‘A’, ‘B’, ‘C’, and ‘?’.
  • The first and $N$-th characters of $S$ are ‘A’.
  • 1ドル ≤ Q ≤ 200,円 000$.
  • 0ドル ≤ X_k$ (1ドル ≤ k ≤ Q$).
  • 0ドル ≤ Y_k$ (1ドル ≤ k ≤ Q$).
  • 0ドル ≤ Z_k$ (1ドル ≤ k ≤ Q$).
  • $X_k + Y_k + Z_k$ is equal to the number of ‘?’ in $S$ (1ドル ≤ k ≤ Q$).
  • $N,ドル $Q,ドル $X_k,ドル $Y_k,ドル $Z_k$ are all integers.

서브태스크

번호배점제한
14

$N ≤ 50$ and the number of ‘?’ in $S$ is less than or equal to 13ドル$.

27

$N ≤ 500$.

313

$N ≤ 5,円 000,ドル $Q ≤ 10$.

418

$N ≤ 5,円 000$.

512

$Q ≤ 10$.

68

$S$ does not contain ‘C’ and $Z_k = 0$ (1ドル ≤ k ≤ Q$).

713

$Z_k = 0$ (1ドル ≤ k ≤ Q$).

825

No additional constraints.

예제 입력 1

9
A??B??C?A
3
1 3 1
4 1 0
0 0 5

예제 출력 1

3
4
4

In the first scenario, Chairman K has to assign 1ドル$ of the 5ドル$ undecided conferences to venue A, 3ドル$ to venue B, and 1ドル$ to venue C. For example, one possible assignment results in the venue information string “ABBBBCCAA”. In this case, the indices $j$ such that the venue for the $j$-th day differs from the venue for the $(j + 1)$-th day are 1ドル,ドル 5ドル,ドル 7ドル,ドル which means there are 3ドル$ such indices. Since it is impossible to reduce this number to 2ドル$ or fewer, the correct output for the first line is 3ドル$.

In the second scenario, Chairman K has to assign 4ドル$ of the 5ドル$ undecided conferences to venue A and 1ドル$ to venue B. For example, one possible assignment results in the venue information string “AAABBACAA”. In this case, the indices $j$ such that the venue for the $j$-th day differs from the venue for the $(j + 1)$-th day are 3ドル,ドル 5ドル,ドル 6ドル,ドル 7ドル,ドル which means there are 4ドル$ such indices. Since it is impossible to reduce this number to 3ドル$ or fewer, the correct output for the second line is 4ドル$.

In the third scenario, Chairman K has to assign all 5ドル$ undecided conferences to venue C. The indices $j$ such that the venue for the $j$-th day differs from the venue for the $(j + 1)$-th day are 1ドル,ドル 3ドル,ドル 4ドル,ドル 8ドル,ドル which means there are 4ドル$ such indices. Therefore, the correct output for the third line is 4ドル$.

This sample input satisfies the constraints of subtasks 1, 2, 3, 4, 5, and 8.

예제 입력 2

12
A???A?B????A
4
0 8 0
2 6 0
7 1 0
3 5 0

예제 출력 2

4
4
2
2

This sample input satisfies the constraints of all the subtasks.

예제 입력 3

28
ACB??B???BCB??B????B?AAA?BBA
26
6 1 6
4 5 4
2 3 8
9 2 2
11 0 2
8 4 1
11 0 2
2 0 11
0 1 12
12 1 0
10 3 0
1 4 8
3 7 3
2 8 3
1 3 9
11 1 1
7 0 6
6 4 3
8 4 1
0 10 3
13 0 0
11 1 1
0 6 7
2 8 3
9 0 4
0 0 13

예제 출력 3

15
11
13
13
15
12
15
15
16
15
13
12
10
9
13
15
15
11
12
9
15
15
11
9
15
17

This sample input satisfies the constraints of subtasks 1, 2, 4, and 8.

힌트

출처

Camp > JOI Spring Training Camp > JOI 2024/2025 Spring Training Camp 3-2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /