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

19187번 - Chocolate is Tasty 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB222272110.606%

문제

A mother wishes to share a chocolate bar among her children. A child can be either a boy or a girl. The children sit in a circle and consecutively take a line of chocolate in clockwise order. At the beginning, the chocolate bar has $n$ rows and $m$ columns. Each boy is greedy and takes one line from the longer side of the chocolate bar. Each girl wishes to keep fit so she takes one line from the shorter side. Mother has to choose from which child she should start to maximize the number of kids that will share the chocolate.

입력

The first line of input consists of $z,ドル the number of test cases. The description of the test cases follows.

Each line consists of two integers $n$ and $m$ separated by a space (1ドル \leq n, m \leq 10^6$). They are followed by a space and a sequence of letters "B" and "G" which identify the children on the circle in clockwise order. The length of the sequence is not greater than 10ドル^6$.

출력

For each test case, print a line with single a interger: the maximal number of children that can eat a chocolate. Do not count the same kid twice even if he/she receive the chocolate twice.

제한

예제 입력 1

3
4 4 GGGGGGG
4 4 BBBBBBB
4 4 GBGBBBG

예제 출력 1

7
4
7

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2015 > Day 6: Jagiellonian U Contest I번

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

출처

대학교 대회

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

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