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

18050번 - Henry Porter and the Palindromic Radius 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
25 초 512 MB155322824.138%

문제

A young wizard, Henry Porter, has just received sad news – the eldest of his family, uncle Markus Radius Palindromus Black, passed away. Uncle Markus had a reputation of being a quite eccentric person, using complicated binary magic, and was also known to be very, very rich.

Black’s will states that Henry should inherit his mysterious chamber of treasures. To enter and claim it, however, the young wizard must say the right password H, which is a word of length n, consisting of characters 0 and 1. Uncle Markus did not tell Henry the password – it certainly wouldn’t be his style. Instead, he computed, for every x = 1, 2, . . . , n, the palindromic radius px – the largest possible integer such that the word H[xpx .. x + px] of length 2px + 1 centered at H[x] exists and is a palindrome. Henry then only received the values p1, . . . , pn. For example, if the password was 10111010, Henry would get the sequence (0, 1, 0, 3, 0, 1, 1, 0).

Henry would prefer Uncle Markus not to test his algorithmic skills while being dead, but, well, there is no one to complain. And he has good friends who can help him! Given the sequence left by Markus in his will, determine all possible passwords that correspond to it. As the will is battered and stained, it might even happen that there is no solution at all.

입력

The first line of input contains the number of test cases z (1 ≤ z ≤ 200 000). The test cases follow, each one in the following format:

A test case consists of two lines. The first line contains a single integer n – the length of both the password and Black’s sequence (2 ≤ n ≤ 1 000 000). The second line contains n integers p1, p2, . . . , pn (0 ≤ pin) – the palindromic radii for all the characters in the password.

The sum of n values over all test cases does not exceed 5 · 107.

출력

For every test case, output first the number k of possible passwords. If k > 0, output in the next k lines all the solutions as {0,1}-sequences. The sequences must be given in lexicographic order.

You may assume that k does not exceed 100.

제한

예제 입력 1

1
8
0 1 0 3 0 1 1 0

예제 출력 1

4
00010000
01000101
10111010
11101111

힌트

출처

ICPC > Regionals > Europe > Central European Regional Contest > Poland Collegiate Programming Contest > AMPPZ 2019 I번

Contest > Open Cup > 2019/2020 Season > Stage 8: Grand Prix of Poland I번

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

출처

대학교 대회

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

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