4. North East South West

Codeforces
IDCF102154
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
Ahmad is playing a game with his friend. The game works like this. Ahmad will start by facing north, then he close his eye. When his friend say "right" he will rotate clockwise by 90 degree. So if he was facing north, he will now face east. If he was facing east, he will now face south. If his friend says "left", he will rotate counter-clockwise by 90 degree. So if he is facing north, he will now face west. If he was facing west, he will now face south. When his friend say "back" he can either rotate clockwise or counter-clockwise by 180 degree. So if he was facing north, he will now face south. If he was facing west, he will now face east. After several command, Ahmad will now guess which direction he is facing. Help Ahmad figure-out which direction he is facing now. Input starts with a number $n, (1 <= n <= 10^5)$. The next $n$ lines each consist of a single word which is either, "left", "right" or "back". Output a single word, which can be either "north", "east", "south", "west". ## Input Input starts with a number $n, (1 <= n <= 10^5)$. The next $n$ lines each consist of a single word which is either, "left", "right" or "back". ## Output Output a single word, which can be either "north", "east", "south", "west". [samples]
**Definitions** Let $ n \in \mathbb{Z} $ be the number of commands, with $ 1 \leq n \leq 10^5 $. Let $ C = (c_1, c_2, \dots, c_n) $ be a sequence of commands, where each $ c_i \in \{\text{left}, \text{right}, \text{back}\} $. Let the initial direction be $ d_0 = \text{north} $. Map directions to integers modulo 4: - $ \text{north} \mapsto 0 $ - $ \text{east} \mapsto 1 $ - $ \text{south} \mapsto 2 $ - $ \text{west} \mapsto 3 $ **Constraints** Each command $ c_i $ transforms the current direction $ d \in \{0,1,2,3\} $ as follows: - If $ c_i = \text{right} $, then $ d \leftarrow (d + 1) \mod 4 $ - If $ c_i = \text{left} $, then $ d \leftarrow (d - 1) \mod 4 $ - If $ c_i = \text{back} $, then $ d \leftarrow (d + 2) \mod 4 $ **Objective** Compute the final direction $ d_n \in \{0,1,2,3\} $ after applying all $ n $ commands sequentially, starting from $ d_0 = 0 $, and output the corresponding direction name.
API Response (JSON)
{
  "problem": {
    "name": "4. North East South West",
    "description": {
      "content": "Ahmad is playing a game with his friend. The game works like this. Ahmad will start by facing north, then he close his eye. When his friend say \"right\" he will rotate clockwise by 90 degree. So if he ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF102154"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Ahmad is playing a game with his friend. The game works like this. Ahmad will start by facing north, then he close his eye. When his friend say \"right\" he will rotate clockwise by 90 degree. So if he ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of commands, with $ 1 \\leq n \\leq 10^5 $.  \nLet $ C = (c_1, c_2, \\dots, c_n) $ be a sequence of commands, where each $ c_i \\in \\{\\text{left}, \\...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments