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

33222번 - Dale ‘n’ Chip 다국어

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

문제

Dale and Chip are preparing the annual Fantastic Party for Chipmunks (FPC). This year, they say, it's much more than a big feast of nuts. In fact, they have prepared a game for their fellow friends. Like any chipmunk, they want their game to be predictable. There is no room for surprises. Last thing you would want is an angry losing chipmunk. Therefore, they will secretly plan the game such that everyone will win and lose exactly one time.

The game goes like this: a group of chipmunks is arranged in a circle. One of them will start the game by turning to their right neighbour and play a round of Rock Paper Scissors. Afterwards, the right neighbour turns to its right neighbour and plays a round of Rock Paper Scissors, and so on. The game ends when everyone has played with their right neighbour exactly once.

Dale has a list of chipmunks that will attend the party, and Chip knows for each of them what power (Rock, Paper, or Scissors) they will always play---% chipmunks are predictable, after all. Not everybody will be at the party at the same time, so they want to prepare the game for several sublists of the list of attendees. For every sublist, calculate the largest possible number of chipmunks picked from that sublist that can be arranged in a circle, such that everyone will be happy, no matter who starts the game.

A happy chipmunk is one that has won and lost exactly once.

입력

The input consists of:

  • One line containing a single integer $n$ (1ドル\leq n\leq 10^4$), the total number of chipmunks on the list of attendees.
  • $n$ lines, each line containing a string ("Rock", "Paper" or "Scissors"), which represents for every attendee what power they will always play.
  • One line containing a single integer $q$ (1ドル\leq q\leq 10^5$), the number of sublists Dale and Chip would like to organise games for.
  • $q$ lines, each containing two integers $s$ and $e$ (1ドル \leq s \leq e\leq n$), representing a sublist of all chipmunks $i$ where $s \leq i \leq e,ドル for which Dale and Chip would like to organise a game.

출력

Output, for each of the $q$ sublists, the largest number of chipmunks that can be arranged into a circle such that every chipmunk is happy.

제한

예제 입력 1

3
Rock
Paper
Scissors
3
1 3
1 2
2 3

예제 출력 1

3
0
0

예제 입력 2

8
Paper
Rock
Rock
Rock
Scissors
Paper
Scissors
Paper
4
3 8
4 6
1 6
2 7

예제 출력 2

6
3
3
3

힌트

출처

University > Delft University of Technology > Freshmen Programming Contest 2022 D번

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

출처

대학교 대회

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

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