Skip to content

Instantly share code, notes, and snippets.

@Naba0123
Created September 19, 2015 07:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save Naba0123/d9ab1d1e7dfd24f84921 to your computer and use it in GitHub Desktop.
<?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