結果
| 問題 |
No.48 ロボットの操縦
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2020-12-27 17:57:53 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 44 ms / 5,000 ms |
| コード長 | 2,813 bytes |
| コンパイル時間 | 3,754 ms |
| コンパイル使用メモリ | 30,804 KB |
| 実行使用メモリ | 31,108 KB |
| 最終ジャッジ日時 | 2024-10-01 18:06:12 |
| 合計ジャッジ時間 | 5,561 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 25 |
コンパイルメッセージ
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;
}