CF1654F.Minimal String Xoration

省选/NOI-

通过率:0%

时间限制:3.00s

内存限制:512MB

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 s0s1s2⋯s2n−1s_0s_1s_2\cdots s_{2^n-1}.

A string tt of length 2n2^n (whose characters are denoted by t0t1t2⋯t2n−1t_0t_1t_2\cdots t_{2^n-1}) is a xoration of ss if there exists an integer jj (0≤j≤2n−10\le j \leq 2^n-1) such that, for each 0≤i≤2n−10 \leq i \leq 2^n-1, ti=si⊕jt_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 a≠ba \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.

给定一个整数 nn 和一个由 2n2^n 个小写英文字母组成的字符串 ss。字符串 ss 的字符表示为 s0s1s2⋯s2n−1s_0s_1s_2\cdots s_{2^n-1}。

长度为 2n2^n 的字符串 tt(其字符表示为 t0t1t2⋯t2n−1t_0t_1t_2\cdots t_{2^n-1})被称为 ss 的一个异或变换(xoration),当且仅当存在一个整数 jj(满足 0≤j≤2n−10 \le j \leq 2^n-1),使得对每个 0≤i≤2n−10 \leq i \leq 2^n-1,均有 ti=si⊕jt_i = s_{i \oplus j}(其中 ⊕\oplus 表示按位异或运算)。

请找出 ss 的字典序最小的异或变换。

字符串 aa 字典序小于字符串 bb,当且仅当满足以下条件之一:

  • aa 是 bb 的真前缀(即 aa 是 bb 的前缀且 a≠ba \ne b);
  • 在 aa 与 bb 首次出现不同字符的位置上,aa 中该位置的字母在字母表中早于 bb 中对应位置的字母。

输入格式

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

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

第一行包含一个整数 nn(1≤n≤181 \le n \le 18)。

第二行包含一个字符串 ss,由 2n2^n 个小写英文字母组成。

输出格式

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

输出一行,包含字符串 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=s0⊕j=s3=t_0 = s_{0 \oplus j} = s_3 = "a";
  • t1=s1⊕j=s2=t_1 = s_{1 \oplus j} = s_2 = "b";
  • t2=s2⊕j=s1=t_2 = s_{2 \oplus j} = s_1 = "c";
  • t3=s3⊕j=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.

在第一个测试中,字符串 s=s = "acba" 的字典序最小异或变换 tt 为 "abca"。它是一个异或变换,因为当 j=3j = 3 时,

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

不存在字典序比 "abca" 更小的 ss 的异或变换。

在第二个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=4j = 4。

在第三个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=11j = 11。

在第四个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=10j = 10。

在第五个测试中,字典序最小的字符串异或变换对应于异或变换定义中选择 j=0j = 0 或 j=1j = 1。

输入解题思路,AI测评打分。不知道怎么写?

首页