問題一覧 > 通常問題

No.1034 Tester Fuppy-san

レベル : / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 198
作問者 : ngtkana / テスター : fuppy_kyopro
お気に入りにしたユーザー ProblemId : 4021 / 自分の提出
問題文最終更新日: 2020-04-24 19:56:58
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Show the original
yukicoder contest 245 (順位表) の他の問題:

Problem Statement

Now I'm going to give you all a quiz about grids, fuppii~♪ First, the beginner level, pi!

Tester Fuppy-san lives in a city shaped like an $ N \times N $ grid. Each cell of the grid has a name, with the top-left cell being $ ( 0, 0 ) $. The cell reached by moving $ i $ cells down and $ j $ cells right from there is named $ ( i, j ) $. Individuality for every cell. This is what we call diversity. (Diver-city, since it's a city.)

The current time is $ 0 $. Tester Fuppy-san is at the top-left cell $ (0, 0) $. Tester Fuppy-san is initially facing right.

From here until "game over", a move is made each time the time changes, pii~♪ Let me explain the rules, pi!

  • A cell that has been visited once must never be visited again.
  • If there is no unvisited cell in any of the four directions, it is "game over" at that point.
  • If a cell exists ahead (in the direction currently faced) and it is unvisited, move there.
  • Otherwise, keep rotating clockwise until an unvisited cell is ahead, and once an unvisited cell is directly ahead, move there.

It can be proven that through this series of moves, Tester Fuppy-san visits all cells and reaches "game over".

Here is an example. If $ N = 4 $, the cells are visited in the following order.

0 1 2 3
11 12 13 4
10 15 14 5
9 8 7 6
A cell labeled $ t $ is visited at time $ t $. For example, at time $ 1 $, the position is $ ( 0, 1 ) $.

Now, here is the question (pii omitted). At what time does Tester Fuppy-san visit the cell $ ( I, J ) $, pi?

Input

$Q$
$N_0\ I_0\ J_0$
$\cdots$
$N_{Q-1}\ I_{Q-1}\ J_{Q-1}$

This problem has multiple test cases. The $ 1 $st line contains the number of test cases $ Q $ as a single integer. Each of the following $ Q $ lines, from the $ 2 $nd line onward, contains the side length of the grid $ N_i $, the vertical position $ I_i $ and the horizontal position $ J_i $ of the cell in question, separated by spaces.

Constraints

  • $ 1 \leq Q \leq 100 $
  • $ 1 \leq N_i \leq 10 ^ 9 $
  • $ 0 \leq I_i < N $
  • $ 0 \leq J_i < N $

Output

$t_0$
$\cdots$
$t_{Q-1}$
For each test case, output the time at which Tester Fuppy-san visits the given cell, separated by newlines. Print a newline at the end.

Sample

Sample 1
Input
1
2 1 1
Output
2

Just for lucky you, here is the big reveal of Tester Fuppy-san's GPS log, pi! 👇

0 1
3 2

提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。