Secret of Tianqiu Valley

시간 제한2초메모리 제한1024 MB

요약
불이 꺼진 횟불을 켜면 양옆 횟불의 상태가 뒤집히는 원형 배치에서, 2n번 이내의 이동으로 모든 횟불을 켜는 방법을 출력하거나 불가능함을 판정한다.
난이도

어려움10점 중 8점

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

문제

In the north tower of Tianqiu Valley's ruins, there are some flame torch puzzles and Lumine the traveler is facing the last and the hardest one.

Source: Genshin Impact Official

There are nn torches in a circle and some torches have been ignited initially. The ii-th and the (i mod n+1)(i \bmod n +1)-th are adjacent for all 1≤i≤n1 \le i \le n.

To solve the puzzle, all the torches should be ignited. In each move, Lumine can ignite an extinguished torch, and the status of the adjacent torches will be reversed affected by the supernatural. That is, each of the adjacent torches will be ignited if it is currently extinguished, or be extinguished if it is currently ignited.

Time is money, Lumine wants to solve the puzzle in 2n2n moves or determine that the puzzle is unsolvable.

입력

There are multiple test cases. The first line of the input contains an integer TT indicating the number of test cases. For each test case:

The first line of the input contains an integer nn (3≤n≤1053 \le n \le 10^5) indicating the number of torches in the circle.

The second line contains a binary string s_1s_2⋯s_ns\_1s\_2\cdots s\_n of length nn (s_i∈’0’,’1’s\_i \in \\{\text{'0'}, \text{'1'}\\}). If s_i=’0’s\_i = \text{'0'} the ii-th torch is extinguished initially; If s_i=’1’s\_i = \text{'1'} the ii-th torch is ignited initially. It is guaranteed that not all the torches have been ignited initially.

It is also guaranteed that the sum of nn of all test cases will not exceed 10610^6.

출력

If the puzzle is unsolvable, output "0" (without quotes).

Otherwise, output an integer kk (1≤k≤2n)(1 \le k \le 2n) in the first line indicating the number of moves Lumine needs to solve the puzzle. Then output a line containing kk integers t_1,t_2,⋯ ,t_kt\_1, t\_2, \cdots, t\_k separated by a space, where t_it\_i indicating that Lumine will ignite the t_it\_i-th torch in the ii-th move. If there are multiple answers print any of them.

힌트

For the first sample test case, the status of the torch will change like this: 0000000000 →\to 1110011100 →\to 0111101111 →\to 1011010110 →\to 0101001010 →\to 0010000100 →\to 0001100011 →\to 1111111111.

예제1

  1. 예제 1

    입력
    2
    5
    00000
    3
    001
    
    예상 출력
    7
    2 5 1 2 3 4 2
    0