Generating patterns

시간 제한1.5초메모리 제한2048 MB

요약
8비트 기본 패턴 B와 XOR 이동을 적용할 순서를 정해, 영에서 시작해 주어진 N비트 문자열을 최소 횟수로 만들고 그 B와 최소 횟수를 출력한다.
난이도

어려움10점 중 9점

유형
문자열 매칭, 동적 계획법, 그리디, 수학
정답자
아직 제출이 없습니다

문제

Sandy is developing a new computer as part of the ambitious System for Binary Compression (SBC) project. This project is part of a major technological challenge known as the Interface for Compact Pattern Coding (ICPC), whose goal is to achieve maximum efficiency in writing large volumes of data.

The SBC proposal is bold: choose a base pattern BB, consisting of 88 bits b_0,…,b_7b\_0, \dots , b\_7, and from it generate any other pattern by applying only simple, fast operations.

Sandy wants to write a sequence of NN bits to memory, with N≥8N ≥ 8, denoted by C=c_0,…,c_N−1C = c\_0, \dots , c\_{N−1}. Initially, memory contains only zeros. She may then repeat the following operation any number of times:

  • Choose an integer ii between −7−7 and N−1N − 1, the position at which BB will be applied;
  • For each position of BB that overlaps the sequence, that is, for every jj from 00 to 77 such that 0≤i+j≤N−10 ≤ i + j ≤ N − 1, replace c_i+jc\_{i+j} with b_j⊕c_i+jb\_j ⊕ c\_{i+j}, where ⊕⊕ denotes the XOR (exclusive OR) operation.

The following example illustrates two applications of the procedure: applying pattern BB to content CC, the final result C′C′ is obtained.

Since the data we want to write to memory is usually not random, Sandy believes that, with a good choice of base pattern BB, it will be possible to produce the desired content with few operations.

To test this hypothesis, she needs your help: given the content CC that must be written to memory, determine the base pattern BB that minimizes the number of operations needed to generate CC as described, and also the number QQ of operations required.

It can be proven that it is always possible to write any content using this procedure. However, for the SBC project to be successful and earn the ICPC seal of excellence, your solution needs to be fast and efficient!

입력

The first line contains an integer NN (8≤N≤40968 ≤ N ≤ 4096), the length of CC.

The second line contains a sequence of NN bits, representing CC, the content that must be written to memory.

출력

Your program should print a single line containing the 88-bit sequence BB, representing the base pattern that minimizes the number of operations, and an integer QQ, representing the minimum number of operations.

If there is more than one pattern BB that minimizes the number of operations, print the one with the smallest integer value when interpreted in base 22, where b_0b\_0 is the most significant bit and b_7b\_7 is the least significant bit.

예제3

  1. 예제 1

    입력
    9
    101001111
    
    예상 출력
    00111101 2
    
  2. 예제 2

    입력
    12
    111111001010
    
    예상 출력
    00010101 3
    
  3. 예제 3

    입력
    10
    0101001111
    
    예상 출력
    01000011 2