I. Card Jousting

Codeforces
IDCF10074I
Time2000ms
Memory32MB
Difficulty
English · Original
Formal · Original
Iahub and Iahubina are playing a card game. Each of them has N cards on which are written numbers. Even if Iahub loves Iahubina very much, he wants to win this game. In order to do that he needs to win all the rounds. A round consists in the choice of the card by Iahubina which will be removed afterwords. Iahub also has to choose a card from his deck, which will be removed afterwords as well. Let B be the card chosen by Iahubina and A the card chosen by Iahub. Iahub can win only if A|B ≥ K. In addition, Iahub has the possibility to interchange the bits from any two cards, but with a cost. Iahub can interchange the bit i from any card from his deck with the bit j, the cost being cost[i[j]]. Find the minimum cost which could lead Iahub to win. The first line of the input contains an integer N (1 ≤ N ≤ 200). The second line contains a vector A[] with N elements, representing the numbers on Iahubina’s cards. The third line contains a vector B[] with N elements, representing the numbers on Iahub’s cards (1 ≤ A[i, B[i] ≤ 256]) On the next line is the integer K (1 ≤ K ≤ 127), followed by 8 lines with 8 values per line, corresponding to the matrix cost[[]] (1 ≤ cost[i[j] ≤ 1000], cost[i[j] = cost[j][i]]). Output the minimum cost which would lead Iahub to win. ## Input The first line of the input contains an integer N (1 ≤ N ≤ 200). The second line contains a vector A[] with N elements, representing the numbers on Iahubina’s cards. The third line contains a vector B[] with N elements, representing the numbers on Iahub’s cards (1 ≤ A[i, B[i] ≤ 256]) On the next line is the integer K (1 ≤ K ≤ 127), followed by 8 lines with 8 values per line, corresponding to the matrix cost[[]] (1 ≤ cost[i[j] ≤ 1000], cost[i[j] = cost[j][i]]). ## Output Output the minimum cost which would lead Iahub to win. [samples]
**Definitions** Let $ N \in \mathbb{Z}^+ $, $ N \leq 200 $. Let $ A = (a_1, \dots, a_N) $, $ B = (b_1, \dots, b_N) $ be sequences of integers with $ 1 \leq a_i, b_i \leq 256 $. Let $ K \in \mathbb{Z}^+ $, $ K \leq 127 $. Let $ C \in \mathbb{R}^{8 \times 8} $ be a symmetric cost matrix with $ c_{i,j} = c_{j,i} \in [1, 1000] $ for $ i,j \in \{0, \dots, 7\} $, representing the cost to swap bit $ i $ and bit $ j $ across any two cards. **Constraints** 1. Each $ a_i, b_i $ is representable as an 8-bit integer. 2. Iahub may perform any number of bit swaps between any two cards in his deck $ B $, where swapping bit $ i $ of card $ b_x $ with bit $ j $ of card $ b_y $ incurs cost $ c_{i,j} $. 3. After swaps, Iahub must assign each of his modified cards to exactly one of Iahubina’s cards (bijection) such that for each pair $ (a_i, b'_j) $, it holds that $ b'_j \mathbin{\&} a_i \geq K $, where $ \& $ denotes bitwise AND. **Objective** Minimize the total cost of bit swaps required to construct a permutation $ \pi: \{1,\dots,N\} \to \{1,\dots,N\} $ and a modified deck $ B' = (b'_1, \dots, b'_N) $, such that: $$ \forall i \in \{1, \dots, N\}, \quad b'_{\pi(i)} \mathbin{\&} a_i \geq K $$ and the cost of transforming $ B $ into $ B' $ via bit swaps is minimized.
API Response (JSON)
{
  "problem": {
    "name": "I. Card Jousting",
    "description": {
      "content": "Iahub and Iahubina are playing a card game. Each of them has N cards on which are written numbers. Even if Iahub loves Iahubina very much, he wants to win this game. In order to do that he needs to wi",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 32768
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10074I"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Iahub and Iahubina are playing a card game. Each of them has N cards on which are written numbers. Even if Iahub loves Iahubina very much, he wants to win this game. In order to do that he needs to wi...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ N \\in \\mathbb{Z}^+ $, $ N \\leq 200 $.  \nLet $ A = (a_1, \\dots, a_N) $, $ B = (b_1, \\dots, b_N) $ be sequences of integers with $ 1 \\leq a_i, b_i \\leq 256 $.  \nLet $ K \\in \\math...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments