RiseOJ는 solved.ac와 제휴 관계가 없습니다. 티어 아이콘 © solved.ac. solved.ac
포럼
USACO0543

Leaders

Silver I 실버 I
난이도
2s
시간 제한
256MB
메모리 제한
0
맞았습니다!!
0
제출 수
0.0%
정답률
레이팅

의견: 0

설명

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.

Problem credits: Mythreya Dharani

제약

SCORING

  • Inputs 3-5: \(N \leq 100\)
  • Inputs 6-10: \(N \leq 3000\)
  • Inputs 11-17: No additional constraints.

Problem credits: Mythreya Dharani

입력 형식

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
설명

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
설명

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

문제 정보

riseoj 작성

출처 올림피아드 > USACO > 2022-2023 > January > Bronze

태그

평가 및 의견

Leaders

개요
출제자 난이도 Silver I 실버 I 의견 0 / 50 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

Leaders

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8