結果

問題 No.48 ロボットの操縦
ユーザー lam6er
提出日時 2025-03-31 17:28:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,416 bytes
コンパイル時間 240 ms
コンパイル使用メモリ 82,816 KB
実行使用メモリ 52,608 KB
最終ジャッジ日時 2025-03-31 17:30:06
合計ジャッジ時間 2,302 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 19 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

x = int(input())
y = int(input())
L = int(input())

dx = abs(x)
dy = abs(y)

min_commands = float('inf')

if x == 0 and y == 0:
    print(0)
    exit()

# Case 1: Y is non-negative (handling north direction)
if y >= 0:
    y_commands = (dy + L - 1) // L if dy != 0 else 0
    if x == 0:
        min_commands = min(min_commands, y_commands)
    else:
        # Consider both east and west for x
        x_commands = (dx + L - 1) // L
        total = y_commands + x_commands + 1
        min_commands = min(min_commands, total)

# Case 2: Y is negative (handling south direction)
if y <= 0:
    if dy > 0:
        y_commands = (dy + L - 1) // L
        current_total = y_commands + 2  # Turning south (2 commands)
        if x != 0:
            x_commands = (dx + L - 1) // L
            current_total += x_commands + 1  # Turning east or west (1 command)
        min_commands = min(min_commands, current_total)

# Case 3: X is zero (handling Y direction)
if x == 0:
    if y >= 0:
        commands = (dy + L - 1) // L if dy > 0 else 0
        min_commands = min(min_commands, commands)
    else:
        commands = ((dy + L - 1) // L + 2) if dy > 0 else 0
        min_commands = min(min_commands, commands)

# Case 4: Y is zero (handling X direction)
if y == 0:
    if x != 0:
        commands = (dx + L - 1) // L + 1  # Turn once to east or west
        min_commands = min(min_commands, commands)

print(min_commands)
0