結果

問題 No.3108 Luke or Bishop
ユーザー Samibare
提出日時 2025-04-19 12:51:25
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 39 ms / 2,000 ms
コード長 544 bytes
コンパイル時間 92 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 10,240 KB
最終ジャッジ日時 2025-04-19 12:51:27
合計ジャッジ時間 1,864 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

def min_moves_to_goal(gx: int, gy: int) -> int:
    # Rook
    if gx == 0 or gy == 0:
        rook_moves = 1 if gx != 0 or gy != 0 else 0  # (0,0)は0手
    else:
        rook_moves = 2

    # Bishop
    if (gx + gy) % 2 != 0:
        bishop_moves = float('inf')  # 行けない
    elif gx == 0 and gy == 0:
        bishop_moves = 0
    elif abs(gx) == abs(gy):
        bishop_moves = 1
    else:
        bishop_moves = 2

    return min(rook_moves, bishop_moves)

# 入力
gx, gy = map(int, input().split())
print(min_moves_to_goal(gx, gy))
0