結果

問題 No.232 めぐるはめぐる (2)
ユーザー 綾地寧々綾地寧々
提出日時 2015-06-30 16:33:31
言語 PHP
(8.2.11)
結果
AC  
実行時間 44 ms / 1,000 ms
コード長 1,963 bytes
コンパイル時間 1,454 ms
コンパイル使用メモリ 18,464 KB
実行使用メモリ 27,064 KB
最終ジャッジ日時 2023-10-12 13:36:05
合計ジャッジ時間 3,138 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 44 ms
26,880 KB
testcase_01 AC 35 ms
27,064 KB
testcase_02 AC 40 ms
26,840 KB
testcase_03 AC 30 ms
26,840 KB
testcase_04 AC 15 ms
18,664 KB
testcase_05 AC 15 ms
18,744 KB
testcase_06 AC 15 ms
18,928 KB
testcase_07 AC 15 ms
18,788 KB
testcase_08 AC 28 ms
27,020 KB
testcase_09 AC 15 ms
18,784 KB
testcase_10 AC 15 ms
18,884 KB
testcase_11 AC 15 ms
18,808 KB
testcase_12 AC 15 ms
18,960 KB
testcase_13 AC 14 ms
18,896 KB
testcase_14 AC 15 ms
18,840 KB
testcase_15 AC 15 ms
18,880 KB
testcase_16 AC 15 ms
18,916 KB
testcase_17 AC 15 ms
18,896 KB
testcase_18 AC 16 ms
18,900 KB
testcase_19 AC 15 ms
18,936 KB
testcase_20 AC 15 ms
18,888 KB
testcase_21 AC 15 ms
18,812 KB
testcase_22 AC 14 ms
18,860 KB
testcase_23 AC 15 ms
18,868 KB
testcase_24 AC 16 ms
18,836 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php
define("INPUT_UP", "^");
define("INPUT_DOWN", "v");
define("INPUT_LEFT", "<");
define("INPUT_RIGHT", ">");
list($t, $a, $b) = explode(" ",trim(fgets(STDIN)));
if ( (max($a, $b) > $t) || (($t == 1) && ($a + $b) == 0) ) {
	echo 'NO'.PHP_EOL;
	return;
}
$move_string = array_fill(0,$t,"");
$move_count = 0;
$wait_count = 0;
for ( $i=0; $i<$t; $i++ ) {
	$move_count++;
	// ちょうどまで周辺待機
	if ( ($a + $b) == 0 ) {
		if ( ($t - $move_count) > 0 ) {
			switch ( $wait_count % 3 ) {
				case 0:
					$move_string[$i] .= INPUT_RIGHT;
					break;
				case 1:
					$move_string[$i] .= INPUT_DOWN;
					break;
				case 2:
					$move_string[$i] .= INPUT_LEFT.INPUT_UP;
				default:
					break;
			}
			$wait_count++;
		}
		else {
			// 周辺待機をしていたとき
			if ( $wait_count != 0 ) {
				switch ( $wait_count % 3 ) {
					case 0:
						$move_string[$i] = substr($move_string[$i-1], 1, 1);
						$move_string[$i-1] = substr($move_string[$i-1], 0, 1);
						break;
					case 1:
						$move_string[$i] .= INPUT_LEFT;
						break;
					case 2:
						$move_string[$i] .= INPUT_LEFT.INPUT_UP;
						break;
					default:
						break;
				}
			}
			// 周辺待機をしていなくて、ちょうど目的地にいるとき
			else if ( $wait_count == 0 ) {
				switch ( $move_string[$i-1] ) {
					case INPUT_UP.INPUT_RIGHT:
						$move_string[$i-1] = INPUT_UP;
						$move_string[$i] = INPUT_RIGHT;
						break;
					case INPUT_UP:
						$move_string[$i-1] .= INPUT_RIGHT;
						$move_string[$i] = INPUT_LEFT;
						break;
					case INPUT_RIGHT:
						$move_string[$i-1] .= INPUT_UP;
						$move_string[$i] = INPUT_DOWN;
						break;
					default:
						break;
				}
			}
		}
	}
	// とにかく目標地点まで移動する
	else {
		if ( $a ) {
			$move_string[$i] .= INPUT_UP;
			$a--;
		}
		if ( $b ) {
			$move_string[$i] .= INPUT_RIGHT;
			$b--;
		}
	}
}

// 答え出力
echo 'YES'.PHP_EOL;
echo implode(PHP_EOL, $move_string).PHP_EOL;
0