結果
問題 | No.48 ロボットの操縦 |
ユーザー | sorch |
提出日時 | 2020-12-27 17:57:53 |
言語 | PHP (8.2.11) |
結果 |
AC
|
実行時間 | 8 ms / 5,000 ms |
コード長 | 2,813 bytes |
コンパイル時間 | 831 ms |
コンパイル使用メモリ | 11,868 KB |
実行使用メモリ | 12,240 KB |
最終ジャッジ日時 | 2023-07-24 22:22:46 |
合計ジャッジ時間 | 2,204 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 7 ms
12,192 KB |
testcase_01 | AC | 7 ms
12,136 KB |
testcase_02 | AC | 7 ms
12,204 KB |
testcase_03 | AC | 7 ms
12,132 KB |
testcase_04 | AC | 7 ms
12,212 KB |
testcase_05 | AC | 7 ms
12,112 KB |
testcase_06 | AC | 7 ms
12,100 KB |
testcase_07 | AC | 7 ms
12,136 KB |
testcase_08 | AC | 7 ms
12,144 KB |
testcase_09 | AC | 7 ms
12,172 KB |
testcase_10 | AC | 7 ms
12,092 KB |
testcase_11 | AC | 6 ms
12,140 KB |
testcase_12 | AC | 7 ms
12,132 KB |
testcase_13 | AC | 7 ms
12,240 KB |
testcase_14 | AC | 7 ms
12,208 KB |
testcase_15 | AC | 7 ms
12,196 KB |
testcase_16 | AC | 7 ms
12,104 KB |
testcase_17 | AC | 7 ms
12,224 KB |
testcase_18 | AC | 7 ms
12,108 KB |
testcase_19 | AC | 7 ms
12,084 KB |
testcase_20 | AC | 8 ms
12,140 KB |
testcase_21 | AC | 7 ms
12,228 KB |
testcase_22 | AC | 7 ms
12,172 KB |
testcase_23 | AC | 7 ms
12,204 KB |
testcase_24 | AC | 7 ms
12,212 KB |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?php /** * @see https://yukicoder.me/problems/75 */ // main $X = trim(fgets(STDIN)); $Y = trim(fgets(STDIN)); $L = trim(fgets(STDIN)); $robot = new Robot($L); $ret = $robot->move($X, $Y); echo $ret . "\n"; class Robot { /** @var array 現在いる座標*/ private $position; /** @var string 現在向いている方向*/ private $orientation; /** @var integer 一回の前進で移動できる最大値 */ private $maxMigrationLength; /** @var RegisterExecHistoryCommand */ private $RegisterExecHistoryCommand; public function __construct(int $maxMigrationLength) { $this->position = [0, 0]; $this->orientation = Direction::NORTH; $this->maxMigrationLength = $maxMigrationLength; } /** * 指定された座標に移動する * * @param integer $x * @param integer $y * @return void */ public function move(int $x, int $y): int { $positionType = $this->getPositionType($x, $y); switch ($positionType) { case PositonType::ZERO: return 0; case PositonType::ON_X: return $this->calcCntExceed($x) + 1; case PositonType::ON_Y: return $this->calcCntExceed($y) + (($y > 0) ? 0 : 2); case PositonType::FIRST_QUADRANT: case PositonType::SECOND_QUADRANT: return $this->calcCntExceed($x) + $this->calcCntExceed($y) + 1; case PositonType::THIRD_QUADRANT: case PositonType::FOURTH_QUADRANT: return $this->calcCntExceed($x) + $this->calcCntExceed($y) + 2; } } private function calcCntExceed($num) { return ceil(abs($num) / $this->maxMigrationLength); } private function getPositionType(int $x, int $y): int { if ($x == 0 && $y == 0) { return PositonType::ZERO; } elseif ($x != 0 && $y == 0) { return PositonType::ON_X; } elseif ($x == 0 && $y != 0) { return PositonType::ON_Y; } elseif ($x > 0 && $y > 0) { return PositonType::FIRST_QUADRANT; } elseif ($x < 0 && $y > 0) { return PositonType::SECOND_QUADRANT; } elseif ($x < 0 && $y < 0) { return PositonType::THIRD_QUADRANT; } elseif ($x > 0 && $y < 0) { return PositonType::FOURTH_QUADRANT; } } } class PositonType { public const FIRST_QUADRANT = 1; public const SECOND_QUADRANT = 2; public const THIRD_QUADRANT = 3; public const FOURTH_QUADRANT = 4; public const ON_X = 5; public const ON_Y = 6; public const ZERO = 7; } class Direction { public const NORTH = 0; public const SOUTH = 1; public const EAST = 2; public const WEST = 3; }