A. The Useless Toy

Codeforces
IDCF834A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Formal · Original
<center>![image](https://espresso.codeforces.com/e20aa30a5a69b31a8d286d9a1d1070f83b65282d.png)</center>Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a kind of useless toy which is very popular nowadays – caramel spinner! Wanting to join the craze, she has immediately bought the strange contraption. Spinners in Sweetland have the form of V-shaped pieces of caramel. Each spinner can, well, spin around an invisible magic axis. At a specific point in time, a spinner can take 4 positions shown below (each one rotated 90 degrees relative to the previous, with the fourth one followed by the first one): <center>![image](https://espresso.codeforces.com/fbb59f31b7bd1f6b125ceabdbc96e21ab2ebf971.png)</center>After the spinner was spun, it starts its rotation, which is described by a following algorithm: the spinner maintains its position for a second then majestically switches to the next position in clockwise or counter-clockwise order, depending on the direction the spinner was spun in. Slastyona managed to have spinner rotating for exactly _n_ seconds. Being fascinated by elegance of the process, she completely forgot the direction the spinner was spun in! Lucky for her, she managed to recall the starting position, and wants to deduct the direction given the information she knows. Help her do this. ## Input There are two characters in the first string – the starting and the ending position of a spinner. The position is encoded with one of the following characters: _v_ (ASCII code 118, lowercase v), _<_ (ASCII code 60), _^_ (ASCII code 94) or _\>_ (ASCII code 62) (see the picture above for reference). Characters are separated by a single space. In the second strings, a single number _n_ is given (0 ≤ _n_ ≤ 109) – the duration of the rotation. It is guaranteed that the ending position of a spinner is a result of a _n_ second spin in any of the directions, assuming the given starting position. ## Output Output _cw_, if the direction is clockwise, _ccw_ – if counter-clockwise, and _undefined_ otherwise. [samples]
在棉花糖城的街道上散步时,Slastyona 发现了一些商贩在售卖一种如今非常流行的无用玩具——焦糖转盘!为了跟上这股潮流,她立即买下了这个奇怪的装置。 在甜点国,转盘呈 V 形焦糖片状。每个转盘可以围绕一条隐形的魔法轴旋转。在某一特定时刻,转盘可以处于以下四种位置之一(每个位置相对于前一个旋转 90 度,第四个位置之后循环回到第一个): 转盘被拨动后,开始旋转,其运动遵循以下算法:转盘在每个位置停留一秒钟,然后根据旋转方向,优雅地切换到顺时针或逆时针方向的下一个位置。 Slastyona 成功让转盘旋转了恰好 #cf_span[n] 秒。她被这一过程的优雅所吸引,完全忘记了转盘最初是顺时针还是逆时针旋转的!幸运的是,她还记得起始位置,并希望根据已知信息推断出旋转方向。请帮助她完成这一推断。 第一行包含两个字符——转盘的起始位置和终止位置。位置用以下字符之一编码:_v_(ASCII 码 #cf_span[118],小写 v)、_<_(ASCII 码 #cf_span[60])、_^_(ASCII 码 #cf_span[94])或 _>_(ASCII 码 #cf_span[62])(参考上图)。字符之间由一个空格分隔。 第二行包含一个单独的数字 #cf_span[n](#cf_span[0 ≤ n ≤ 109])——旋转的持续时间。 保证在给定起始位置的前提下,转盘的终止位置是经过 #cf_span[n] 秒旋转后,在任意方向上的结果。 如果方向是顺时针,请输出 _cw_;如果是逆时针,请输出 _ccw_;否则输出 _undefined_。 ## Input 第一行包含两个字符——转盘的起始位置和终止位置。位置用以下字符之一编码:_v_(ASCII 码 #cf_span[118],小写 v)、_<_(ASCII 码 #cf_span[60])、_^_(ASCII 码 #cf_span[94])或 _>_(ASCII 码 #cf_span[62])(参考上图)。字符之间由一个空格分隔。第二行包含一个单独的数字 #cf_span[n](#cf_span[0 ≤ n ≤ 109])——旋转的持续时间。保证在给定起始位置的前提下,转盘的终止位置是经过 #cf_span[n] 秒旋转后,在任意方向上的结果。 ## Output 如果方向是顺时针,请输出 _cw_;如果是逆时针,请输出 _ccw_;否则输出 _undefined_。 [samples]
**Definitions** Let $ P = \{ \text{v}, \text{<}, \text{^}, \text{>} \} $ be the set of spinner positions, ordered clockwise as: $$ \text{v} \to \text{>} \to \text{^} \to \text{<} \to \text{v} $$ Assign indices: - $ \text{v} \mapsto 0 $ - $ \text{>} \mapsto 1 $ - $ \text{^} \mapsto 2 $ - $ \text{<} \mapsto 3 $ Let $ s \in P $ be the starting position, $ e \in P $ the ending position, and $ n \in \mathbb{Z}_{\geq 0} $ the duration of rotation ($ 0 \leq n \leq 10^9 $). Let $ f: P \to \mathbb{Z}_4 $ be the index mapping: $ f(\text{v}) = 0, f(\text{>}) = 1, f(\text{^}) = 2, f(\text{<}) = 3 $. **Constraints** 1. $ n \in \{0, 1, \dots, 10^9\} $ 2. The ending position $ e $ is reachable from $ s $ after $ n $ seconds under either clockwise or counter-clockwise rotation. **Objective** Determine the rotation direction: - Let $ d_{\text{cw}} = (f(e) - f(s)) \mod 4 $ - Let $ d_{\text{ccw}} = (f(s) - f(e)) \mod 4 $ Then: - If $ d_{\text{cw}} \equiv n \mod 4 $ and $ d_{\text{ccw}} \not\equiv n \mod 4 $, output **cw** - If $ d_{\text{ccw}} \equiv n \mod 4 $ and $ d_{\text{cw}} \not\equiv n \mod 4 $, output **ccw** - If $ d_{\text{cw}} \equiv n \mod 4 $ and $ d_{\text{ccw}} \equiv n \mod 4 $, output **undefined**
Samples
Input #1
^ >
1
Output #1
cw
Input #2
< ^
3
Output #2
ccw
Input #3
^ v
6
Output #3
undefined
API Response (JSON)
{
  "problem": {
    "name": "A. The Useless Toy",
    "description": {
      "content": "<center>![image](https://espresso.codeforces.com/e20aa30a5a69b31a8d286d9a1d1070f83b65282d.png)</center>Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF834A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "<center>![image](https://espresso.codeforces.com/e20aa30a5a69b31a8d286d9a1d1070f83b65282d.png)</center>Walking through the streets of Marshmallow City, Slastyona have spotted some merchants selling a ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "在棉花糖城的街道上散步时,Slastyona 发现了一些商贩在售卖一种如今非常流行的无用玩具——焦糖转盘!为了跟上这股潮流,她立即买下了这个奇怪的装置。\n\n在甜点国,转盘呈 V 形焦糖片状。每个转盘可以围绕一条隐形的魔法轴旋转。在某一特定时刻,转盘可以处于以下四种位置之一(每个位置相对于前一个旋转 90 度,第四个位置之后循环回到第一个):\n\n转盘被拨动后,开始旋转,其运动遵循以下算法:转盘在每个...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ P = \\{ \\text{v}, \\text{<}, \\text{^}, \\text{>} \\} $ be the set of spinner positions, ordered clockwise as:  \n$$ \\text{v} \\to \\text{>} \\to \\text{^} \\to \\text{<} \\to \\text{v} $$  ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments