結果
問題 |
No.48 ロボットの操縦
|
ユーザー |
![]() |
提出日時 | 2025-04-15 22:31:39 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 36 ms / 5,000 ms |
コード長 | 1,403 bytes |
コンパイル時間 | 226 ms |
コンパイル使用メモリ | 82,028 KB |
実行使用メモリ | 53,568 KB |
最終ジャッジ日時 | 2025-04-15 22:33:32 |
合計ジャッジ時間 | 1,903 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 25 |
ソースコード
import sys x = int(sys.stdin.readline()) y = int(sys.stdin.readline()) L = int(sys.stdin.readline()) if x == 0 and y == 0: print(0) sys.exit() def compute_rotation_cost(current, target): clockwise = (target - current) % 4 counter = (current - target) % 4 return min(clockwise, counter) if x == 0: if y >= 0: moves = (y + L - 1) // L print(moves) else: rotates = 2 moves = (-y + L - 1) // L print(rotates + moves) sys.exit() if y == 0: rotates = 1 moves = (abs(x) + L - 1) // L print(rotates + moves) sys.exit() # Both x and y are non-zero # Case 1: Process Y first y_dir = 0 if y >= 0 else 2 x_dir = 1 if x >= 0 else 3 rotate_y = 0 if y >= 0 else 2 current_after_y = y_dir target_x = x_dir rotate_x = compute_rotation_cost(current_after_y, target_x) moves_y = (abs(y) + L - 1) // L moves_x = (abs(x) + L - 1) // L case1 = rotate_y + moves_y + rotate_x + moves_x # Case 2: Process X first x_dir_case = 1 if x >= 0 else 3 y_dir_case = 0 if y >= 0 else 2 rotate_x_case = 1 # Rotate from North to East/West (1 step) current_after_x = x_dir_case target_y_case = y_dir_case rotate_y_case = compute_rotation_cost(current_after_x, target_y_case) moves_x_case = (abs(x) + L - 1) // L moves_y_case = (abs(y) + L - 1) // L case2 = rotate_x_case + moves_x_case + rotate_y_case + moves_y_case print(min(case1, case2))