B. Working with Locks 2

Codeforces
IDCF10253B
Time2000ms
Memory256MB
Difficulty
English · Original
Formal · Original
104 days of summer vacation and school comes along just to end it! For the rest of summer vacation, Dr. Doofenshmirtz will occasionally be doing things to take over the Greater Tri-State Area and Perry the Platypus has to stop him. The good news is that Agent P has managed to make an imprint of a set of keys and duplicate all of them. The bad news is that each day, Perry will be locked inside a different room with a different lock. And the set of keys he has might not have a correct key to open the lock on some days. There are a total of 104 different locks, one for each day of summer vacation, and there are 104 different keys. As before, each key can open a lock if the difference between their numbers is exactly one. To be more explicit: You will be given the set of keys that Perry the Platypus has as well as the lock numbers on the days that Dr. Doofenshmirtz will be active. Output how many days Perry can successfully stop the mad doctor. Each test case consists of four lines. The first line contains an integer $k$, the number of keys that Perry has. The second line contains $k$ space-separated integers representing each key $k_i$. The third line contains an integer $L$, the number of locks. The fourth line contains $L$ space-separated integers, representing each lock $L_i$. *Constraints* $1 <= k <= 104$ $1 <= k_i <= 104$ $1 <= L <= 104$ $1 <= L_i <= 104$ No two $k_i$s are the same. No two $L_i$s are the same. Output a single integer, the number of days that Perry can successfully stop Dr. Doofenshmirtz. ## Input Each test case consists of four lines.The first line contains an integer $k$, the number of keys that Perry has.The second line contains $k$ space-separated integers representing each key $k_i$.The third line contains an integer $L$, the number of locks.The fourth line contains $L$ space-separated integers, representing each lock $L_i$.*Constraints*$1 <= k <= 104$ $1 <= k_i <= 104$ $1 <= L <= 104$ $1 <= L_i <= 104$ No two $k_i$s are the same. No two $L_i$s are the same. ## Output Output a single integer, the number of days that Perry can successfully stop Dr. Doofenshmirtz. [samples]
**Definitions** Let $ n \in \mathbb{Z}^+ $ be the number of craters and days. Let $ m \in \mathbb{Z}^+ $ be the number of craters Roro visits per day. Let $ S = (s_1, s_2, \dots, s_n) \in \{0,1\}^n $ be the initial state of craters, where $ s_i = 1 $ means open, $ s_i = 0 $ means filled. Let $ D = (d_1, d_2, \dots, d_n) $ be a sequence of day-wise commands, where each $ d_k \subseteq \{1, 2, \dots, n\} $ with $ |d_k| = m $, denotes the set of craters visited on day $ k $. **Constraints** 1. $ 1 \leq t \leq 1000 $ 2. For each test case: - $ 1 \leq n \leq 20 $ - $ 1 \leq m \leq n $ - $ s_i \in \{0,1\} $ for all $ i \in \{1, \dots, n\} $ **Dynamics** Let $ c_k = (c_{k,1}, \dots, c_{k,n}) \in \{0,1\}^n $ be the state of craters at the end of day $ k $, with $ c_0 = S $. For each day $ k \in \{1, \dots, n\} $: - For each crater $ i \in \{1, \dots, n\} $: $$ c_{k,i} = \begin{cases} 0 & \text{if } i \in d_k \text{ and } c_{k-1,i} = 0 \\ 1 & \text{if } i \in d_k \text{ and } c_{k-1,i} = 1 \\ c_{k-1,i} & \text{otherwise} \end{cases} $$ (i.e., visiting a filled crater opens it; visiting an open crater fills it.) **Objective** Find a sequence $ D = (d_1, \dots, d_n) $ such that $ c_n = (0, 0, \dots, 0) $, or determine that no such sequence exists. If impossible: output "_CATACLYSM IMMINENT - TIME TO HOARD FACE MASKS_" Otherwise: output $ n $ lines, each containing $ m $ distinct integers (1-indexed) representing $ d_k $.
API Response (JSON)
{
  "problem": {
    "name": "B. Working with Locks 2",
    "description": {
      "content": "104 days of summer vacation and school comes along just to end it! For the rest of summer vacation, Dr. Doofenshmirtz will occasionally be doing things to take over the Greater Tri-State Area and Perr",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10253B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "104 days of summer vacation and school comes along just to end it! For the rest of summer vacation, Dr. Doofenshmirtz will occasionally be doing things to take over the Greater Tri-State Area and Perr...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z}^+ $ be the number of craters and days.  \nLet $ m \\in \\mathbb{Z}^+ $ be the number of craters Roro visits per day.  \nLet $ S = (s_1, s_2, \\dots, s_n) \\in \\{0,1\\...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments