This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
# 霧島京子 | |
// 配列数は要らない | |
fgets(STDIN); | |
// 盤面 | |
$cells = explode(' ', trim(fgets(STDIN))); | |
$goal = count($cells) - 1; | |
$comeflag = array_fill(0, count($cells), false); | |
// 入力数 | |
$num = trim(fgets(STDIN)); | |
while ($num-- > 0) { | |
$dice = trim(fgets(STDIN)); | |
// 初期処理 | |
$now_state = 0; | |
$comeflag = array_fill(0, count($cells), false); | |
$next_state = $now_state + $dice; | |
// メインループ | |
while (true) { | |
// 範囲外への移動 | |
if ($next_state < 0 || $goal < $next_state ) { | |
echo "No\n"; | |
break; | |
} | |
// ゴールではなく0 | |
if ($next_state != $goal && $cells[$next_state] == 0) { | |
echo "No\n"; | |
break; | |
} | |
// 既視感 | |
if ($comeflag[$next_state] == true) { | |
echo "No\n"; | |
break; | |
} | |
// ゲームクリア | |
if ($next_state == $goal) { | |
echo "Yes\n"; | |
break; | |
} | |
// 更新処理 | |
$comeflag[$next_state] = true; | |
$now_state = $next_state; | |
$next_state += $cells[$now_state]; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment