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

15469번 - Mixing Coins 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB122484044.444%

문제

Misaka likes to shoot coins as a powerful railgun.

She prepares a line of coins to fight crime. To produce a stronger coin, she mixes coins together. However, coins with different materials are not compatible to each other, so she only mixes coins with same material together.

Here’s the steps Misaka makes coins:

  1. Find first three consecutive coins with same material from the beginning of the line
  2. Take them out from the line
  3. Mix together and produce a new coin with same material
  4. Put the new coin at the end of line

She repeatedly do these steps until she can’t produce new coins anymore.

Misaka wants to know how many coins she will have. Please help her count coins rapidly!

입력

On the first line there is a single integer T indicating the number of test cases.

The first line of each test case contains an integer N indicating the number of groups of consecutive coins Misaka has. All coins are in a single line.

Then N lines follow, each line containing a character ci and an integer ni, denoting that there are ni consecutive coins with material ci for i-th group of consecutive coins, behind (i − 1)-th.

You may assume:

  • T ≤ 10
  • 1 ≤ N ≤ 105
  • 1 ≤ ni ≤ 109
  • ci is an uppercase alphabet, ci ≠ ci+1 for 1 ≤ i < N

출력

For each test case, output an integer in one line, indicating the number of coins after Misaka doing the steps of making coins as many as possible.

제한

예제 입력 1

2
3
A 3
B 1
A 2
3
A 2
B 3
A 2

예제 출력 1

2
3

힌트

출처

ICPC > Regionals > Asia Pacific > Taiwan > Taiwan Online Programming Contest > TOPC 2017 D번

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

출처

대학교 대회

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

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