CF1654F.Minimal String Xoration

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

You are given an integer nn and a string ss consisting of 2n2^n lowercase letters of the English alphabet. The characters of the string ss are s0s1s2s2n1s_0s_1s_2\cdots s_{2^n-1} .

A string tt of length 2n2^n (whose characters are denoted by t0t1t2t2n1t_0t_1t_2\cdots t_{2^n-1} ) is a xoration of ss if there exists an integer jj ( 0j2n10\le j \leq 2^n-1 ) such that, for each 0i2n10 \leq i \leq 2^n-1 , ti=sijt_i = s_{i \oplus j} (where \oplus denotes the operation bitwise XOR).

Find the lexicographically minimal xoration of ss .

A string aa is lexicographically smaller than a string bb if and only if one of the following holds:

  • aa is a prefix of bb , but aba \ne b ;
  • in the first position where aa and bb differ, the string aa has a letter that appears earlier in the alphabet than the corresponding letter in bb .

输入格式

The first line contains a single integer nn ( 1n181 \le n \le 18 ).

The second line contains a string ss consisting of 2n2^n lowercase letters of the English alphabet.

输出格式

Print a single line containing the lexicographically minimal xoration of ss .

输入输出样例

  • 输入#1

    2
    acba

    输出#1

    abca
  • 输入#2

    3
    bcbaaabb

    输出#2

    aabbbcba
  • 输入#3

    4
    bdbcbccdbdbaaccd

    输出#3

    abdbdccacbdbdccb
  • 输入#4

    5
    ccfcffccccccffcfcfccfffffcccccff

    输出#4

    cccccffffcccccffccfcffcccccfffff
  • 输入#5

    1
    zz

    输出#5

    zz

说明/提示

In the first test, the lexicographically minimal xoration tt of s=s = "acba" is "abca". It's a xoration because, for j=3j = 3 ,

  • t0=s0j=s3=t_0 = s_{0 \oplus j} = s_3 = "a";
  • t1=s1j=s2=t_1 = s_{1 \oplus j} = s_2 = "b";
  • t2=s2j=s1=t_2 = s_{2 \oplus j} = s_1 = "c";
  • t3=s3j=s0=t_3 = s_{3 \oplus j} = s_0 = "a".

There isn't any xoration of ss lexicographically smaller than "abca".In the second test, the minimal string xoration corresponds to choosing j=4j = 4 in the definition of xoration.

In the third test, the minimal string xoration corresponds to choosing j=11j = 11 in the definition of xoration.

In the fourth test, the minimal string xoration corresponds to choosing j=10j = 10 in the definition of xoration.

In the fifth test, the minimal string xoration corresponds to choosing either j=0j = 0 or j=1j = 1 in the definition of xoration.

首页