結果
| 問題 | 
                            No.48 ロボットの操縦
                             | 
                    
| コンテスト | |
| ユーザー | 
                             lam6er
                         | 
                    
| 提出日時 | 2025-04-15 22:24:28 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 34 ms / 5,000 ms | 
| コード長 | 1,532 bytes | 
| コンパイル時間 | 233 ms | 
| コンパイル使用メモリ | 81,900 KB | 
| 実行使用メモリ | 53,816 KB | 
| 最終ジャッジ日時 | 2025-04-15 22:26:45 | 
| 合計ジャッジ時間 | 1,942 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge1 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 | 
ソースコード
def min_rotate_steps(current, target):
    diff = (target - current) % 4
    return min(diff, 4 - diff)
X = int(input())
Y = int(input())
L = int(input())
if X == 0 and Y == 0:
    print(0)
    exit()
min_commands = float('inf')
dir_x = None
if X != 0:
    if X > 0:
        dir_x = 1  # East
    else:
        dir_x = 3  # West
dir_y = None
if Y != 0:
    if Y > 0:
        dir_y = 0  # North
    else:
        dir_y = 2  # South
# Case when X is 0, only Y direction
if X == 0:
    if dir_y is not None:
        move_y = (abs(Y) + L - 1) // L
        rotate_y = min_rotate_steps(0, dir_y)
        total = move_y + rotate_y
        min_commands = min(min_commands, total)
# Case when Y is 0, only X direction
elif Y == 0:
    if dir_x is not None:
        move_x = (abs(X) + L - 1) // L
        rotate_x = min_rotate_steps(0, dir_x)
        total = move_x + rotate_x
        min_commands = min(min_commands, total)
# Both X and Y are non-zero
else:
    # Case 1: Y first, then X
    rotate_y = min_rotate_steps(0, dir_y)
    rotate_x_case1 = min_rotate_steps(dir_y, dir_x)
    total_rotate_case1 = rotate_y + rotate_x_case1
    move_y = (abs(Y) + L - 1) // L
    move_x = (abs(X) + L - 1) // L
    case1 = move_y + move_x + total_rotate_case1
    # Case 2: X first, then Y
    rotate_x = min_rotate_steps(0, dir_x)
    rotate_y_case2 = min_rotate_steps(dir_x, dir_y)
    total_rotate_case2 = rotate_x + rotate_y_case2
    case2 = move_x + move_y + total_rotate_case2
    min_commands = min(case1, case2)
print(min_commands)
            
            
            
        
            
lam6er