結果

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

ソースコード

diff #

def solve_chess_puzzle(gx: int, gy: int) -> int:
    # Base case - already at target
    if gx == 0 and gy == 0:
        return 0
        
    # Rook (Luke) moves
    # Can reach in 1 move if target is on same row/column
    # Otherwise needs 2 moves (horizontal + vertical)
    rook_moves = 1 if gx == 0 or gy == 0 else 2
    
    # Bishop moves
    # Can reach in 1 move if target is on diagonal (|x| = |y|)
    # Otherwise needs 2 moves
    bishop_moves = 1 if abs(gx) == abs(gy) else 2
    
    return min(rook_moves, bishop_moves)

def main():
    # Read input as space-separated integers
    try:
        gx, gy = map(int, input().strip().split())
        result = solve_chess_puzzle(gx, gy)
        # Ensure output is a single integer
        print(result)
    except ValueError:
        print("Invalid input format")

if __name__ == "__main__":
    main()
0