C. Berzerk

Codeforces
IDCF787C
Time4000ms
Memory256MB
Difficulty
dpgames
English · Original
Chinese · Translation
Formal · Original
Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are _n_ objects numbered from 1 to _n_ arranged in a circle (in clockwise order). Object number 1 is a black hole and the others are planets. There's a monster in one of the planet. Rick and Morty don't know on which one yet, only that he's not initially in the black hole, but Unity will inform them before the game starts. But for now, they want to be prepared for every possible scenario. <center>![image](https://espresso.codeforces.com/511a6a2fad36df3d1e996557879abf28e1412577.png)</center>Each one of them has a set of numbers between 1 and _n_ - 1 (inclusive). Rick's set is _s_1 with _k_1 elements and Morty's is _s_2 with _k_2 elements. One of them goes first and the player changes alternatively. In each player's turn, he should choose an arbitrary number like _x_ from his set and the monster will move to his _x_\-th next object from its current position (clockwise). If after his move the monster gets to the black hole he wins. Your task is that for each of monster's initial positions and who plays first determine if the starter wins, loses, or the game will stuck in an infinite loop. In case when player can lose or make game infinity, it more profitable to choose infinity game. ## Input The first line of input contains a single integer _n_ (2 ≤ _n_ ≤ 7000) — number of objects in game. The second line contains integer _k_1 followed by _k_1 distinct integers _s_1, 1, _s_1, 2, ..., _s_1, _k_1 — Rick's set. The third line contains integer _k_2 followed by _k_2 distinct integers _s_2, 1, _s_2, 2, ..., _s_2, _k_2 — Morty's set 1 ≤ _k__i_ ≤ _n_ - 1 and 1 ≤ _s__i_, 1, _s__i_, 2, ..., _s__i_, _k__i_ ≤ _n_ - 1 for 1 ≤ _i_ ≤ 2. ## Output In the first line print _n_ - 1 words separated by spaces where _i_\-th word is "_Win_" (without quotations) if in the scenario that Rick plays first and monster is initially in object number _i_ + 1 he wins, "_Lose_" if he loses and "_Loop_" if the game will never end. Similarly, in the second line print _n_ - 1 words separated by spaces where _i_\-th word is "_Win_" (without quotations) if in the scenario that Morty plays first and monster is initially in object number _i_ + 1 he wins, "_Lose_" if he loses and "_Loop_" if the game will never end. [samples]
里克和莫蒂正在玩他们自己的版本的《Berzerk》(这与著名的《Berzerk》游戏毫无关系)。这个游戏需要巨大的空间,因此他们用电脑来玩。 在这个游戏中,有 #cf_span[n] 个物体,编号从 #cf_span[1] 到 #cf_span[n],按顺时针方向排列成一个圆圈。编号为 #cf_span[1] 的物体是黑洞,其余的是行星。有一个怪物位于其中一个行星上。里克和莫蒂尚不知道它在哪个行星上,只知道它初始时不在黑洞中,但Unity会在游戏开始前告知他们。但目前,他们希望为每种可能的情况做好准备。 他们每人拥有一组介于 #cf_span[1] 和 #cf_span[n - 1](含)之间的数字。里克的集合是 #cf_span[s1],包含 #cf_span[k1] 个元素;莫蒂的集合是 #cf_span[s2],包含 #cf_span[k2] 个元素。其中一人先手,然后两人轮流进行。在每个玩家的回合中,他必须从自己的集合中选择一个任意数字 #cf_span[x],怪物将从当前位置顺时针移动 #cf_span[x] 个位置。如果移动后怪物到达黑洞,则该玩家获胜。 你的任务是:对于怪物的每个初始位置以及谁先手,判断先手玩家是赢、输,还是游戏会陷入无限循环。当玩家可以选择输或使游戏无限进行时,选择无限循环更有利。 输入的第一行包含一个整数 #cf_span[n](#cf_span[2 ≤ n ≤ 7000])——游戏中的物体数量。 第二行包含整数 #cf_span[k1],后跟 #cf_span[k1] 个互不相同的整数 #cf_span[s1, 1, s1, 2, ..., s1, k1] —— 里克的集合。 第三行包含整数 #cf_span[k2],后跟 #cf_span[k2] 个互不相同的整数 #cf_span[s2, 1, s2, 2, ..., s2, k2] —— 莫蒂的集合。 #cf_span[1 ≤ ki ≤ n - 1] 且 #cf_span[1 ≤ si, 1, si, 2, ..., si, ki ≤ n - 1] 对于 #cf_span[1 ≤ i ≤ 2]。 第一行输出 #cf_span[n - 1] 个用空格分隔的单词,其中第 #cf_span[i] 个单词为 "_Win_"(不含引号),表示当里克先手且怪物初始位于第 #cf_span[i + 1] 个物体时他获胜;为 "_Lose_" 表示他失败;为 "_Loop_" 表示游戏将永远进行下去。 类似地,第二行输出 #cf_span[n - 1] 个用空格分隔的单词,其中第 #cf_span[i] 个单词为 "_Win_"(不含引号),表示当莫蒂先手且怪物初始位于第 #cf_span[i + 1] 个物体时他获胜;为 "_Lose_" 表示他失败;为 "_Loop_" 表示游戏将永远进行下去。 ## Input 输入的第一行包含一个整数 #cf_span[n](#cf_span[2 ≤ n ≤ 7000])——游戏中的物体数量。第二行包含整数 #cf_span[k1],后跟 #cf_span[k1] 个互不相同的整数 #cf_span[s1, 1, s1, 2, ..., s1, k1] —— 里克的集合。第三行包含整数 #cf_span[k2],后跟 #cf_span[k2] 个互不相同的整数 #cf_span[s2, 1, s2, 2, ..., s2, k2] —— 莫蒂的集合。#cf_span[1 ≤ ki ≤ n - 1] 且 #cf_span[1 ≤ si, 1, si, 2, ..., si, ki ≤ n - 1] 对于 #cf_span[1 ≤ i ≤ 2]。 ## Output 第一行输出 #cf_span[n - 1] 个用空格分隔的单词,其中第 #cf_span[i] 个单词为 "_Win_"(不含引号),表示当里克先手且怪物初始位于第 #cf_span[i + 1] 个物体时他获胜;为 "_Lose_" 表示他失败;为 "_Loop_" 表示游戏将永远进行下去。类似地,第二行输出 #cf_span[n - 1] 个用空格分隔的单词,其中第 #cf_span[i] 个单词为 "_Win_"(不含引号),表示当莫蒂先手且怪物初始位于第 #cf_span[i + 1] 个物体时他获胜;为 "_Lose_" 表示他失败;为 "_Loop_" 表示游戏将永远进行下去。 [samples]
**Definitions** Let $ n \in \mathbb{Z} $, $ n \geq 2 $, be the number of objects arranged in a circle, indexed $ 0 $ to $ n-1 $, where object $ 0 $ is the black hole. Let $ S_1 \subseteq \{1, 2, \dots, n-1\} $ be Rick’s move set, with $ |S_1| = k_1 $. Let $ S_2 \subseteq \{1, 2, \dots, n-1\} $ be Morty’s move set, with $ |S_2| = k_2 $. Let $ p \in \{1, 2\} $ denote the current player: $ p=1 $ for Rick, $ p=2 $ for Morty. Let $ s \in \{0, 1, \dots, n-1\} $ be the current position of the monster, with $ s \neq 0 $ initially. A state is a pair $ (s, p) $, representing monster position $ s $ and player $ p $ to move. **Transition** From state $ (s, p) $, player $ p $ chooses a move $ x \in S_p $, and transitions to state $ ((s + x) \bmod n, 3-p) $. If $ (s + x) \bmod n = 0 $, the current player wins immediately. **Objective** For each initial position $ s \in \{1, 2, \dots, n-1\} $: - Compute the outcome when Rick starts ($ p=1 $): output "Win", "Lose", or "Loop". - Compute the outcome when Morty starts ($ p=2 $): output "Win", "Lose", or "Loop". **Game Theory Rules** - A state $ (s, p) $ is a **Win** if there exists a move $ x \in S_p $ such that $ (s + x) \bmod n = 0 $, OR if there exists a move to a **Lose** state for the opponent. - A state $ (s, p) $ is a **Lose** if for all moves $ x \in S_p $, the resulting state is **Win** for the opponent. - A state $ (s, p) $ is a **Loop** if it is neither Win nor Lose (i.e., no winning move, and at least one move leads to Loop). **Output** - First line: for $ s = 1 $ to $ n-1 $, outcome when $ p = 1 $ (Rick starts). - Second line: for $ s = 1 $ to $ n-1 $, outcome when $ p = 2 $ (Morty starts).
Samples
Input #1
5
2 3 2
3 1 2 3
Output #1
Lose Win Win Loop
Loop Win Win Win
Input #2
8
4 6 2 3 4
2 3 6
Output #2
Win Win Win Win Win Win Win
Lose Win Lose Lose Win Lose Lose
API Response (JSON)
{
  "problem": {
    "name": "C. Berzerk",
    "description": {
      "content": "Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there a",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 4000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF787C"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer.\n\nIn this game there a...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "里克和莫蒂正在玩他们自己的版本的《Berzerk》(这与著名的《Berzerk》游戏毫无关系)。这个游戏需要巨大的空间,因此他们用电脑来玩。\n\n在这个游戏中,有 #cf_span[n] 个物体,编号从 #cf_span[1] 到 #cf_span[n],按顺时针方向排列成一个圆圈。编号为 #cf_span[1] 的物体是黑洞,其余的是行星。有一个怪物位于其中一个行星上。里克和莫蒂尚不知道它在哪个行...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $, $ n \\geq 2 $, be the number of objects arranged in a circle, indexed $ 0 $ to $ n-1 $, where object $ 0 $ is the black hole.  \nLet $ S_1 \\subseteq \\{1, 2, \\...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments