結果
| 問題 |
No.232 めぐるはめぐる (2)
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2015-06-30 16:33:31 |
| 言語 | PHP (843.2) |
| 結果 |
AC
|
| 実行時間 | 64 ms / 1,000 ms |
| コード長 | 1,963 bytes |
| コンパイル時間 | 3,927 ms |
| コンパイル使用メモリ | 32,144 KB |
| 実行使用メモリ | 38,328 KB |
| 最終ジャッジ日時 | 2024-09-14 12:34:31 |
| 合計ジャッジ時間 | 6,152 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge6 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 22 |
コンパイルメッセージ
No syntax errors detected in Main.php
ソースコード
<?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;