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

27561번 - Leaders 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 1024 MB63626020942.052%

문제

Farmer John has $N$ cows (2ドル \leq N \leq 10^5$). Each cow has a breed that is either Guernsey or Holstein. As is often the case, the cows are standing in a line, numbered 1ドル \ldots N$ in this order.

Over the course of the day, each cow writes down a list of cows. Specifically, cow $i$'s list contains the range of cows starting with herself (cow $i$) up to and including cow $E_i$ ($i \leq E_i \leq N$).

FJ has recently discovered that each breed of cow has exactly one distinct leader. FJ does not know who the leaders are, but he knows that each leader must have a list that includes all the cows of their breed, or the other breed's leader (or both).

Help FJ count the number of pairs of cows that could be leaders. It is guaranteed that there is at least one possible pair.

입력

The first line contains $N$.

The second line contains a string of length $N,ドル with the $i$th character denoting the breed of the $i$th cow (G meaning Guernsey and H meaning Holstein). It is guaranteed that there is at least one Guernsey and one Holstein.

The third line contains $E_1 \dots E_N$.

출력

Output the number of possible pairs of leaders.

제한

예제 입력 1

4
GHHG
2 4 3 4

예제 출력 1

1

The only valid leader pair is $(1, 2)$. Cow 1ドル$'s list contains the other breed's leader (cow 2ドル$). Cow 2ドル$'s list contains all cows of her breed (Holstein).

No other pairs are valid. For example, $(2,4)$ is invalid since cow 4ドル$'s list does not contain the other breed's leader, and it also does not contain all cows of her breed.

예제 입력 2

3
GGH
2 3 3

예제 출력 2

2

There are two valid leader pairs, $(1, 3)$ and $(2, 3)$.

힌트

출처

Olympiad > USA Computing Olympiad > 2022-2023 Season > USACO 2023 January Contest > Bronze 1번

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

출처

대학교 대회

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

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