結果
| 問題 |
No.3108 Luke or Bishop
|
| コンテスト | |
| ユーザー |
kakur41
|
| 提出日時 | 2025-04-20 03:43:48 |
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
| 結果 |
AC
|
| 実行時間 | 27 ms / 2,000 ms |
| コード長 | 1,930 bytes |
| コンパイル時間 | 316 ms |
| コンパイル使用メモリ | 12,032 KB |
| 実行使用メモリ | 10,240 KB |
| 最終ジャッジ日時 | 2025-04-20 03:43:50 |
| 合計ジャッジ時間 | 1,747 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 26 |
ソースコード
# coding: utf-8
import sys
def solve():
# 標準入力から Gx と Gy を受け取る
# Read Gx and Gy from standard input
gx, gy = map(int, sys.stdin.readline().split())
# Case 0: ゴールが原点の場合
# Case 0: If the goal is the origin
if gx == 0 and gy == 0:
print(0)
return
# Case 1: 1手で到達可能な場合
# Case 1: If reachable in 1 move
# ルークで1手 (x軸またはy軸上)
# Rook in 1 move (on x-axis or y-axis)
is_rook_1_move = (gx == 0 or gy == 0)
# ビショップで1手 (y=x または y=-x 上)
# Bishop in 1 move (on y=x or y=-x)
is_bishop_1_move = (gx == gy or gx == -gy)
if is_rook_1_move or is_bishop_1_move:
print(1)
return
# Case 2: 2手で到達可能な場合
# Case 2: If reachable in 2 moves
# 上記の1手の条件を満たさない場合、ルークでは必ず2手で到達可能。
# If the 1-move conditions above are not met, the rook can always reach in 2 moves.
# ビショップで到達可能か (座標の偶奇が一致するか) を確認する。
# Check if the bishop can reach (if the parity of coordinates matches).
# (gx + gy) % 2 == 0 は、gx と gy の偶奇が一致することと同値。
# (gx + gy) % 2 == 0 is equivalent to gx and gy having the same parity.
is_bishop_reachable = ((gx + gy) % 2 == 0)
# 1手で到達できず、ビショップで到達可能なら、ルークもビショップも2手。最小2手。
# If not reachable in 1 move and bishop can reach, both rook and bishop take 2 moves. Minimum is 2.
# 1手で到達できず、ビショップで到達不可能でも、ルークが2手で到達できるので最小2手。
# If not reachable in 1 move and bishop cannot reach, the rook can still reach in 2 moves. Minimum is 2.
print(2)
# 関数を実行
# Execute the function
solve()
kakur41