G. Graphic Settings

Codeforces
IDCF863G
Time2000ms
Memory256MB
Difficulty
English · Original
Chinese · Translation
Formal · Original
Recently Ivan bought a new computer. Excited, he unpacked it and installed his favourite game. With his old computer Ivan had to choose the worst possible graphic settings (because otherwise the framerate would be really low), but now he wants to check, maybe his new computer can perform well even with the best possible graphics? There are _m_ graphics parameters in the game. _i_\-th parameter can be set to any positive integer from 1 to _a__i_, and initially is set to _b__i_ (_b__i_ ≤ _a__i_). So there are different combinations of parameters. Ivan can increase or decrease any of these parameters by 1; after that the game will be restarted with new parameters (and Ivan will have the opportunity to check chosen combination of parameters). Ivan wants to try all _p_ possible combinations. Also he wants to return to the initial settings after trying all combinations, because he thinks that initial settings can be somehow best suited for his hardware. But Ivan doesn't really want to make a lot of restarts. So he wants you to tell the following: * If there exists a way to make exactly _p_ changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then Ivan wants to know this way. * Otherwise, if there exists a way to make exactly _p_ - 1 changes to try all possible combinations (including the initial one), then Ivan wants to know this way. Help Ivan by showing him the way to change parameters! ## Input The first line of input contains one integer number _m_ (1 ≤ _m_ ≤ 6). The second line contains _m_ integer numbers _a_1, _a_2, ..., _a__m_ (2 ≤ _a__i_ ≤ 1000). It is guaranteed that . The third line contains _m_ integer numbers _b_1, _b_2, ..., _b__m_ (1 ≤ _b__i_ ≤ _a__i_). ## Output If there is a way to make exactly _p_ changes (each change either decreases or increases some parameter by 1) to try all possible combinations and return to initial combination, then output _Cycle_ in the first line. Then _p_ lines must follow, each desribing a change. The line must be either _inc x_ (increase parameter _x_ by 1) or _dec x_ (decrease it). Otherwise, if there is a way to make exactly _p_ - 1 changes to try all possible combinations (including the initial one), then output _Path_ in the first line. Then _p_ - 1 lines must follow, each describing the change the same way as mentioned above. Otherwise, output _No_. [samples]
最近,Ivan 购买了一台新电脑。他非常兴奋,拆开包装并安装了自己最喜欢的游戏。在旧电脑上,Ivan 不得不选择最差的图形设置(否则帧率会非常低),但现在他想检查一下,他的新电脑是否即使在最佳图形设置下也能良好运行? 游戏中有 #cf_span[m] 个图形参数。第 #cf_span[i] 个参数可以设置为从 #cf_span[1] 到 #cf_span[ai] 的任意正整数,初始值为 #cf_span[bi](#cf_span[bi ≤ ai])。因此共有 种参数组合。Ivan 可以将任意一个参数增加或减少 #cf_span[1];之后游戏会重启并使用新的参数设置(Ivan 将有机会检查所选的参数组合)。 Ivan 希望尝试所有 #cf_span[p] 种可能的组合。此外,他希望在尝试完所有组合后恢复到初始设置,因为他认为初始设置可能最适合他的硬件。但 Ivan 并不想进行太多次重启。 因此,他希望你告诉他: 帮助 Ivan 找到一种改变参数的方法! 输入的第一行包含一个整数 #cf_span[m](#cf_span[1 ≤ m ≤ 6])。 第二行包含 #cf_span[m] 个整数 #cf_span[a1, a2, ..., am](#cf_span[2 ≤ ai ≤ 1000])。保证 。 第三行包含 #cf_span[m] 个整数 #cf_span[b1, b2, ..., bm](#cf_span[1 ≤ bi ≤ ai])。 如果存在一种方法,恰好进行 #cf_span[p] 次改变(每次改变将某个参数增加或减少 #cf_span[1]),以尝试所有可能的组合并返回到初始组合,则在第一行输出 _Cycle_。随后必须输出 #cf_span[p] 行,每行描述一次改变。每行必须是 _inc x_(将第 #cf_span[x] 个参数增加 #cf_span[1])或 _dec x_(将第 #cf_span[x] 个参数减少 #cf_span[1])。 否则,如果存在一种方法,恰好进行 #cf_span[p - 1] 次改变,以尝试所有可能的组合(包括初始组合),则在第一行输出 _Path_。随后必须输出 #cf_span[p - 1] 行,每行描述改变的方式同上。 否则,输出 _No_。 ## Input 输入的第一行包含一个整数 #cf_span[m](#cf_span[1 ≤ m ≤ 6])。第二行包含 #cf_span[m] 个整数 #cf_span[a1, a2, ..., am](#cf_span[2 ≤ ai ≤ 1000])。保证 。第三行包含 #cf_span[m] 个整数 #cf_span[b1, b2, ..., bm](#cf_span[1 ≤ bi ≤ ai])。 ## Output 如果存在一种方法,恰好进行 #cf_span[p] 次改变(每次改变将某个参数增加或减少 #cf_span[1]),以尝试所有可能的组合并返回到初始组合,则在第一行输出 _Cycle_。随后必须输出 #cf_span[p] 行,每行描述一次改变。每行必须是 _inc x_(将第 #cf_span[x] 个参数增加 #cf_span[1])或 _dec x_(将第 #cf_span[x] 个参数减少 #cf_span[1])。否则,如果存在一种方法,恰好进行 #cf_span[p - 1] 次改变,以尝试所有可能的组合(包括初始组合),则在第一行输出 _Path_。随后必须输出 #cf_span[p - 1] 行,每行描述改变的方式同上。否则,输出 _No_。 [samples]
**Definitions** Let $ m \in \mathbb{Z}^+ $, $ m \leq 6 $. Let $ \mathbf{a} = (a_1, a_2, \dots, a_m) \in \mathbb{Z}^m $ with $ 2 \leq a_i \leq 1000 $. Let $ \mathbf{b} = (b_1, b_2, \dots, b_m) \in \mathbb{Z}^m $ with $ 1 \leq b_i \leq a_i $. Let $ p = \prod_{i=1}^m a_i $. Let $ S = \prod_{i=1}^m \{1, 2, \dots, a_i\} $ be the set of all parameter combinations. Let $ \mathbf{b} \in S $ be the initial state. A *move* is an operation that increments or decrements exactly one coordinate $ x \in \{1, \dots, m\} $ by 1, resulting in a new state in $ S $. **Constraints** 1. All states visited must lie in $ S $. 2. Each move changes exactly one parameter by $ \pm 1 $. 3. No state may be visited more than once (except possibly the initial state at the end). **Objective** Determine whether there exists a sequence of moves such that: - **Case 1 (Cycle):** The sequence visits all $ p $ states exactly once, ends at $ \mathbf{b} $, and uses exactly $ p $ moves. - **Case 2 (Path):** The sequence visits all $ p $ states exactly once, starts at $ \mathbf{b} $, ends at some state $ \neq \mathbf{b} $, and uses exactly $ p - 1 $ moves. - **Case 3 (No):** Neither of the above is possible. Output: - “Cycle” followed by $ p $ moves if Case 1 holds. - “Path” followed by $ p - 1 $ moves if Case 2 holds. - “No” otherwise.
Samples
Input #1
1
3
1
Output #1
Path
inc 1
inc 1
Input #2
1
3
2
Output #2
No
Input #3
2
3 2
1 1
Output #3
Cycle
inc 1
inc 1
inc 2
dec 1
dec 1
dec 2
API Response (JSON)
{
  "problem": {
    "name": "G. Graphic Settings",
    "description": {
      "content": "Recently Ivan bought a new computer. Excited, he unpacked it and installed his favourite game. With his old computer Ivan had to choose the worst possible graphic settings (because otherwise the frame",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF863G"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Recently Ivan bought a new computer. Excited, he unpacked it and installed his favourite game. With his old computer Ivan had to choose the worst possible graphic settings (because otherwise the frame...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "最近,Ivan 购买了一台新电脑。他非常兴奋,拆开包装并安装了自己最喜欢的游戏。在旧电脑上,Ivan 不得不选择最差的图形设置(否则帧率会非常低),但现在他想检查一下,他的新电脑是否即使在最佳图形设置下也能良好运行?\n\n游戏中有 #cf_span[m] 个图形参数。第 #cf_span[i] 个参数可以设置为从 #cf_span[1] 到 #cf_span[ai] 的任意正整数,初始值为 #cf_...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ m \\in \\mathbb{Z}^+ $, $ m \\leq 6 $.  \nLet $ \\mathbf{a} = (a_1, a_2, \\dots, a_m) \\in \\mathbb{Z}^m $ with $ 2 \\leq a_i \\leq 1000 $.  \nLet $ \\mathbf{b} = (b_1, b_2, \\dots, b_m) \\i...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments