Feeding Beavers

시간 제한2.5초메모리 제한256 MB

요약
2N개의 접시를 N마리의 비버에게 둘씩 나눠 주되, 비버 번호가 커질수록 만족도의 합이 작아지지 않고 각 합의 홀짝이 주어진 문자열과 일치하도록 배정하고, 가능하면 그 예를 출력한다.
난이도

보통10점 중 7점

유형
그리디, 수학, 구현, 정렬
정답자
아직 제출이 없습니다

문제

It’s dinner time, and Busy Beaver has to feed his baby beavers.

Busy Beaver has NN baby beavers, numbered from 11 to NN. The older baby beavers have bigger indices than the younger ones; for example, beaver 11 is the youngest while beaver NN is the oldest.

Busy Beaver also has 2N2N dishes, which are numbered from 11 to 2N2N. If a beaver eats dish ii, its satisfaction will increase by ii. Each beaver starts with 00 satisfaction.

Now, Busy Beaver wants to distribute the dishes amongst his baby beavers subject to the following constraints:

  • Each beaver should get exactly two dishes.
  • After all dishes are consumed, older beavers should have at least as much satisfaction as younger beavers. Formally, for any i,ji,j with 1≤i\<j≤N1\leq i\<j\leq N, beaver ii’s satisfaction should not exceed beaver jj’s satisfaction.
  • The parity of beaver ii’s satisfaction should be c_ic\_i (odd or even).

Determine if there exists a way to feed all NN beavers that respects these constraints. Additionally, if the task is possible, print any valid assignment of dishes to beavers.

입력

Each test contains multiple test cases. The first line contains a single integer TT (1≤T≤1041\leq T\leq 10^4) --- the number of test cases. The description of each test case follows.

The first line of each test case contains an integer NN (1≤N≤1051\le N\le 10^5) --- the number of baby beavers.

The second line of each test case contains a string cc of length NN, where each of the characters c_ic\_i is either ‘O’ or ‘E’. If c_ic\_i is ‘O’, the beaver ii wants its satisfaction to be an odd number. If c_ic\_i is ‘E’, the beaver ii wants its satisfaction to be an even number.

It is guaranteed that the sum of NN across all test cases is no more than 10510^5.

출력

For each test case, if it is possible to feed the beavers, output “YES” (without quotes) on the first line. Next, print NN lines describing how to feed each beaver. The ii-th of these lines should contain two integers, which denote the indices of the two dishes that will be given to beaver ii.

If it is impossible to feed the beavers, output “NO” (without quotes).

You can output “YES” and “NO” in any case. (For example, strings “yES”, “yes” and “Yes” will be recognized as a positive response.)

예제1

  1. 예제 1

    입력
    3
    4
    OEEO
    7
    OEOEOEO
    6
    OOOOOO
    
    예상 출력
    YES
    2 3
    5 1
    4 8
    7 6
    NO
    YES
    1 12
    2 11
    3 10
    4 9
    5 8
    6 7