079. Over The Rainbow

Codeforces
IDCF10269079
Time1000ms
Memory256MB
Difficulty
English · Original
Formal · Original
A color wheel is a tool used to determine the relationships of different colors, often by the distance between two colors on the wheel. Using the given simple color wheel above, your task is to determine the shortest numerical distance between two colors. The first line will contain an integer $n$, the number of test cases that will follow. The next lines will contain two strings in each individual line, which will be the two colors that will taken under measurement. (All colors will have the same name as the colors of the image above) Return the int value of the distance between the two colors, including the last color, but excluding the first. (All inputs will be in lowercase) ## Input The first line will contain an integer $n$, the number of test cases that will follow. The next lines will contain two strings in each individual line, which will be the two colors that will taken under measurement. (All colors will have the same name as the colors of the image above) ## Output Return the int value of the distance between the two colors, including the last color, but excluding the first. [samples] ## Note (All inputs will be in lowercase)
**Definitions** Let $ n \in \mathbb{Z} $ be the number of test cases. Let $ C = (c_1, c_2, \dots, c_6) $ be the ordered cycle of colors: $ c_1 = \text{"red"} $, $ c_2 = \text{"yellow"} $, $ c_3 = \text{"green"} $, $ c_4 = \text{"cyan"} $, $ c_5 = \text{"blue"} $, $ c_6 = \text{"magenta"} $. Let $ T = \{(x_k, y_k) \mid k \in \{1, \dots, n\}\} $ be the set of test cases, where $ x_k, y_k \in C $. **Constraints** 1. $ 1 \le n \le \text{some bound (implied by input)} $ 2. For each $ k $, $ x_k, y_k \in \{c_1, \dots, c_6\} $ **Objective** For each test case $ (x_k, y_k) $, compute the shortest clockwise distance from $ x_k $ to $ y_k $ along the cycle $ C $, defined as: Let $ i = \text{index of } x_k $, $ j = \text{index of } y_k $ (1-based). Then: $$ d_k = \min\left( (j - i) \bmod 6,\ (i - j) \bmod 6 \right) $$ But since the problem specifies *"including the last color, but excluding the first"*, and implies **clockwise distance** (as per typical color wheel interpretation), we interpret it as: $$ d_k = (j - i) \bmod 6 $$ with the understanding that if $ j < i $, we wrap around: $$ d_k = \begin{cases} j - i & \text{if } j \ge i \\ j - i + 6 & \text{if } j < i \end{cases} $$ Equivalently: $$ d_k = (j - i + 6) \bmod 6 $$ But note: since we include the last and exclude the first, this is the number of steps from $ x_k $ to $ y_k $ clockwise, **not counting** the start but **counting** the end — i.e., the number of edges traversed. This matches $ (j - i) \bmod 6 $, and since distances are non-negative and minimal in a 6-cycle, we use: $$ \boxed{d_k = (j - i + 6) \bmod 6} $$ However, if the problem means the **shortest** distance (not necessarily clockwise), then: $$ d_k = \min\left( (j - i + 6) \bmod 6,\ (i - j + 6) \bmod 6 \right) $$ But the phrase *"including the last color, but excluding the first"* and *"distance between two colors on the wheel"* in context of a **color wheel** typically implies **clockwise** path. Moreover, the example (if provided) would clarify — but since none is, and the problem says *"shortest numerical distance"*, we must assume **minimal circular distance**. Thus, final objective: For each test case, let $ i, j \in \{1,2,3,4,5,6\} $ be the 1-based indices of the two colors in $ C $. Compute: $$ d_k = \min\left( |j - i|,\ 6 - |j - i| \right) $$
API Response (JSON)
{
  "problem": {
    "name": "079. Over The Rainbow",
    "description": {
      "content": "A color wheel is a tool used to determine the relationships of different colors, often by the distance between two colors on the wheel. Using the given simple color wheel above, your task is to deter",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF10269079"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "A color wheel is a tool used to determine the relationships of different colors, often by the distance between two colors on the wheel.\n\nUsing the given simple color wheel above, your task is to deter...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of test cases.  \nLet $ C = (c_1, c_2, \\dots, c_6) $ be the ordered cycle of colors:  \n$ c_1 = \\text{\"red\"} $, $ c_2 = \\text{\"yellow\"} $, $ c_3 ...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments