D. XOR Permutations

Codeforces
IDCF10215D
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
A bitwise XOR takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is $1$ if both bits are different (only one of them is $1$ and the other is $0$), but will be $0$ if both bits are the same (both are $0$ or both are $1$). For example, the bitwise XOR of the patterns $0101$ and $1100$ is $1001$. In this problem, you are given $3$ binary strings of lengths $10$ digits such that all digits are either $0$ or $1$. You can swap any two digits in the same string infinitely, but you cannot swap two digits from two different strings. Your task is to rearrange digits in the given strings in a way such that the bitwise XOR of the strings after rearranging their digits is as largest as possible. Can you? The first line contains an integer $T$ ($1 <= T <= 250$) specifying the number of test cases. Each test case consists of $3$ lines each of which contains a binary string of length $10$ digits such that all digits are either $0$ or $1$. For each test, print a single line containing a binary string of length $10$ representing the largest value of bitwise XOR that can be optioned by rearranging digits in each string. A binary string $x$ is larger than a binary string $y$ if after converting both strings to the decimal representation, the decimal value of string $x$ is larger than the decimal value of string $y$. For example, string "_1100_" is larger than string "_0101_" because its decimal value $12$, while the decimal value of string "_0101_" is $5$. In the first test case, you can rearrange the given strings as follow: ## Input The first line contains an integer $T$ ($1 <= T <= 250$) specifying the number of test cases.Each test case consists of $3$ lines each of which contains a binary string of length $10$ digits such that all digits are either $0$ or $1$. ## Output For each test, print a single line containing a binary string of length $10$ representing the largest value of bitwise XOR that can be optioned by rearranging digits in each string.A binary string $x$ is larger than a binary string $y$ if after converting both strings to the decimal representation, the decimal value of string $x$ is larger than the decimal value of string $y$. For example, string "_1100_" is larger than string "_0101_" because its decimal value $12$, while the decimal value of string "_0101_" is $5$. [samples] ## Note In the first test case, you can rearrange the given strings as follow: "_0000101011_" $arrow.r$ "_0000111100_" "_0001010101_" $arrow.r$ "_1111000000_" "_0010010000_" $arrow.r$ "_0000000011_"
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of robots. Let $ A = (a_1, a_2, \dots, a_n) \in (\mathbb{Z}^+)^n $, where $ a_i $ is the time robot $ i $ needs to cover the distance after receiving the signal. Let $ S \subseteq \{1, 2, \dots, n\} $ be a non-empty subset of active signal devices. For each robot $ i $, define $ x_i(S) = \min_{j \in S} |i - j| $, the distance to the nearest active device. The finish time of robot $ i $ under $ S $ is $ f_i(S) = x_i(S) + a_i $. Let $ k_i(S) = \left| \{ j \neq i \mid f_j(S) < f_i(S) \} \right| $. The rank (place) of robot $ i $ under $ S $ is $ r_i(S) = k_i(S) + 1 $. **Constraints** 1. $ 1 \leq n \leq 400{,}000 $ 2. $ 1 \leq a_i \leq 10^9 $ 3. $ S \neq \emptyset $ **Objective** Given $ p \in \{1, 2\} $: - If $ p = 1 $, compute for each $ i \in \{1, \dots, n\} $: $$ \min_{\substack{S \subseteq \{1,\dots,n\} \\ S \neq \emptyset}} r_i(S) $$ - If $ p = 2 $, compute for each $ i \in \{1, \dots, n\} $: $$ \max_{\substack{S \subseteq \{1,\dots,n\} \\ S \neq \emptyset}} r_i(S) $$
API Response (JSON)
{
  "problem": {
    "name": "D. XOR Permutations",
    "description": {
      "content": "A bitwise XOR takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is $1$ if both bits are different (",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10215D"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A bitwise XOR takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is $1$ if both bits are different (...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of robots.  \nLet $ A = (a_1, a_2, \\dots, a_n) \\in (\\mathbb{Z}^+)^n $, where $ a_i $ is the time robot $ i $ needs to cover the distance after...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments