B. Lara Croft and the New Game

Codeforces
IDCF976B
Time2000ms
Memory256MB
Difficulty
implementationmath
English · Original
Chinese · Translation
Formal · Original
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy. Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of _n_ rows and _m_ columns. Cell (_x_, _y_) is the cell in the _x_\-th row in the _y_\-th column. Lara can move between the neighbouring by side cells in all four directions. Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (_n_, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2\-nd column, one cell up. She moves until she runs out of non-visited cells. _n_ and _m_ given are such that she always end up in cell (1, 2). Lara has already moved to a neighbouring cell _k_ times. Can you determine her current position? ## Input The only line contains three integers _n_, _m_ and _k_ (2 ≤ _n_, _m_ ≤ 109, **_n_ is always even**, 0 ≤ _k_ < _n_·_m_). Note that _k_ doesn't fit into 32\-bit integer type! ## Output Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves _k_ times. [samples] ## Note Here is her path on matrix 4 by 3: <center>![image](https://espresso.codeforces.com/61e9f9d459b4794ae490c526463f732a1988ab0d.png)</center>
你可能听说过今年即将推出的《古墓丽影》系列新作。你也可能看过它的预告片。不过你肯定错过了其剧情的核心内容,因此让我来揭开这个秘密。 Lara 将要探索另一个危险的地下城。游戏设计师决定使用经典的二维环境。地下城可以表示为一个包含 #cf_span[n] 行和 #cf_span[m] 列的矩形矩阵。单元格 #cf_span[(x, y)] 表示第 #cf_span[x] 行、第 #cf_span[y] 列的格子。Lara 可以向四个方向(上、下、左、右)移动到相邻的格子。 此外,她已经为自己规划了一条避开所有陷阱的路径。她从单元格 #cf_span[(1, 1)](即矩阵的左上角)进入地下城,然后一直向下移动到单元格 #cf_span[(n, 1)](即左下角)。接着,她以“蛇形”方式移动:向右走到最右端,向上一格,再向左走到第 #cf_span[2] 列,再向上一格。她持续移动,直到所有未访问过的格子都被走完。题目保证 #cf_span[n] 和 #cf_span[m] 的取值使得她最终一定会停在单元格 #cf_span[(1, 2)]。 Lara 已经移动了 #cf_span[k] 次。你能确定她当前的位置吗? 输入仅一行包含三个整数 #cf_span[n], #cf_span[m] 和 #cf_span[k](#cf_span[2 ≤ n, m ≤ 109],*#cf_span[n] 总是偶数*,#cf_span[0 ≤ k < n·m])。注意:#cf_span[k] 超出了 #cf_span[32]-位整数类型的范围! 请输出 Lara 移动 #cf_span[k] 次后所在的单元格(即行号和列号)。 ## Input 输入仅一行包含三个整数 #cf_span[n], #cf_span[m] 和 #cf_span[k](#cf_span[2 ≤ n, m ≤ 109],*#cf_span[n] 总是偶数*,#cf_span[0 ≤ k < n·m])。注意:#cf_span[k] 超出了 #cf_span[32]-位整数类型的范围! ## Output 请输出 Lara 移动 #cf_span[k] 次后所在的单元格(即行号和列号)。 [samples] ## Note 以下是她在 4 行 3 列矩阵中的路径:
**Definitions** Let $ n, m \in \mathbb{Z} $ with $ n $ even, $ 2 \leq n, m \leq 10^9 $, and $ k \in \mathbb{Z} $ with $ 0 \leq k < n \cdot m $. Let the dungeon be an $ n \times m $ grid with cell coordinates $ (x, y) $, where $ x \in \{1, \dots, n\} $ is the row (top to bottom) and $ y \in \{1, \dots, m\} $ is the column (left to right). Lara’s path consists of two phases: 1. **Vertical descent**: From $ (1,1) $ to $ (n,1) $, moving downward. 2. **Snake traversal**: Starting at $ (n,1) $, she moves right along row $ n $ to $ (n,m) $, then up to $ (n-1,m) $, then left to $ (n-1,2) $, then up to $ (n-2,2) $, then right to $ (n-2,m) $, and so on, alternating direction per row, until ending at $ (1,2) $. **Constraints** 1. $ n $ is even. 2. $ k < n \cdot m $. **Objective** Determine Lara’s position $ (x, y) $ after exactly $ k $ moves, starting from $ (1,1) $. The path is structured as: - Phase 1: $ n - 1 $ moves downward from $ (1,1) $ to $ (n,1) $. - Phase 2: Snake traversal covering the remaining $ n \cdot m - n $ cells, starting at $ (n,1) $, moving right, then up, then left, etc., row by row, skipping column 1 after the first column. In Phase 2, each pair of rows (from bottom to top) forms a "cycle" of $ 2(m - 1) $ moves: - Right along row $ i $: from $ (i,1) $ to $ (i,m) $ → $ m - 1 $ moves. - Up to $ (i-1,m) $. - Left along row $ i-1 $: from $ (i-1,m) $ to $ (i-1,2) $ → $ m - 2 $ moves. - Up to $ (i-2,2) $. Thus, each two-row block (e.g., rows $ n $ and $ n-1 $, then $ n-2 $ and $ n-3 $, etc.) consumes $ 2(m - 1) $ moves. Let $ \text{remaining} = k - (n - 1) $. If $ \text{remaining} < 0 $, Lara is still in Phase 1: - $ x = 1 + k $, $ y = 1 $. Otherwise, in Phase 2: Let $ \text{cycle\_len} = 2(m - 1) $. Let $ \text{cycle\_idx} = \left\lfloor \frac{\text{remaining}}{\text{cycle\_len}} \right\rfloor $, so she has completed $ \text{cycle\_idx} $ full two-row cycles. Then $ \text{offset} = \text{remaining} \mod \text{cycle\_len} $. The current row is $ x = n - 2 \cdot \text{cycle\_idx} - \delta $, where $ \delta = 0 $ if $ \text{offset} < m - 1 $, else $ \delta = 1 $. The column depends on direction: - If $ \text{offset} < m - 1 $: moving right → $ y = 1 + \text{offset} $. - Else: moving left → $ y = m - (\text{offset} - (m - 1)) = 2m - 1 - \text{offset} $. **Final Position:** If $ k < n - 1 $: $$ (x, y) = (1 + k, 1) $$ Else: Let $ r = k - (n - 1) $, $ c = 2(m - 1) $, $ i = \left\lfloor \frac{r}{c} \right\rfloor $, $ o = r \mod c $. - If $ o < m - 1 $: $$ (x, y) = (n - 2i, 1 + o) $$ - Else: $$ (x, y) = (n - 2i - 1, 2m - 1 - o) $$
Samples
Input #1
4 3 0
Output #1
1 1
Input #2
4 3 11
Output #2
1 2
Input #3
4 3 7
Output #3
3 2
API Response (JSON)
{
  "problem": {
    "name": "B. Lara Croft and the New Game",
    "description": {
      "content": "You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift t",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF976B"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift t...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "你可能听说过今年即将推出的《古墓丽影》系列新作。你也可能看过它的预告片。不过你肯定错过了其剧情的核心内容,因此让我来揭开这个秘密。\n\nLara 将要探索另一个危险的地下城。游戏设计师决定使用经典的二维环境。地下城可以表示为一个包含 #cf_span[n] 行和 #cf_span[m] 列的矩形矩阵。单元格 #cf_span[(x, y)] 表示第 #cf_span[x] 行、第 #cf_span[...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n, m \\in \\mathbb{Z} $ with $ n $ even, $ 2 \\leq n, m \\leq 10^9 $, and $ k \\in \\mathbb{Z} $ with $ 0 \\leq k < n \\cdot m $.  \n\nLet the dungeon be an $ n \\times m $ grid with cell...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments