아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

A + B Problem

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

요약
이진 문자열을 주어진 길이의 두 부분수열로 나눠 두 이진수의 합이 최대가 되도록 만들고, 그 합을 이진수로 출력한다.
난이도

보통10점 중 5점

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

문제

A binary string is a string consisting only of digits "00" and "11". Given a binary string ss of length (n+m)(n + m), please divide it into two subsequences A=a_1a_2…a_nA = a\_1 a\_2 \ldots a\_n of length nn and B=b_1b_2…b_mB = b\_1 b\_2 \ldots b\_m of length mm such that each digit in ss belongs to exactly one subsequence.

Let ff be the function that transforms a sequence of "00" and "11" into a binary integer. For example, f(1,0,1,0)=1010_2f(\\{1, 0, 1, 0\\}) = 1010\_2 and f(0,0,1,0)=10_2f(\\{0, 0, 1, 0\\}) = 10\_2. Your task is to find such AA and BB that maximize (f(A)+f(B))(f(A) + f(B)).

Recall that a subsequence of a string is a sequence that can be derived by deleting some characters (possibly none) from the string without changing the order of the remaining characters.

입력

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 contains two integers nn and mm (1≤n,m≤1051 \le n, m \le 10^5) indicating the lengths of the desired subsequences.

The second line contains a binary string ss (∣s∣=n+m|s| = n + m, s\_i \in \\{\text{"0"}, \text{"1"}\\}).

It is guaranteed that the sum of (n+m)(n + m) of all test cases will not exceed 2⋅1062 \cdot 10^6.

출력

For each test case, output one line containing a binary integer indicating the largest possible result of (f(A)+f(B))(f(A) + f(B)). Note that (f(A)+f(B))(f(A) + f(B)) should be printed as a binary integer with no leading zeroes, while AA and BB are sequences, and leading zeros are allowed in the sequences.

힌트

We now use underline to indicate subsequence AA in the binary string.

For the first sample test case, a valid solution is to divide the binary string into 1‾000101‾\underline{1}000\underline{101} such that f(1,1,0,1)+f(0,0,0)=1101_2+0_2=1101_2f(\\{1, 1, 0, 1\\}) + f(\\{0, 0, 0\\}) = 1101\_2 + 0\_2 = 1101\_2.

For the second sample test case, a valid solution is to divide the binary string into 1‾11‾1\underline{1}1\underline{1}1 such that f(1,1)+f(1,1)=11_2+11_2=110_2f(\\{1, 1\\}) + f(\\{1, 1\\}) = 11\_2 + 11\_2 = 110\_2.

예제1

  1. 예제 1

    입력
    3
    4 3
    1000101
    2 2
    1111
    1 1
    00
    
    예상 출력
    1101
    110
    0