Advertisement
Guest User

ladybug

a guest
Nov 14th, 2019
297
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. <?php
  2. $n = intval(readline());
  3. $arr = array_map('intval', explode(' ', readline()));
  4. $cells = [];
  5. for ($i = 0; $i < $n; $i++) {
  6.     $cells[$i] = 0;
  7. }
  8. for ($i = 0; $i < count($arr); $i++) {
  9.     if (array_key_exists($arr[$i], $cells)) {
  10.         $cells[$arr[$i]] = 1;
  11.     }
  12. }
  13. $command = readline();
  14. while ($command != 'end') {
  15.     $arr = explode(' ', $command);
  16.     $position = intval($arr[0]);
  17.     $direction = $arr[1];
  18.     $shift = intval($arr[2]);
  19.     if (array_key_exists($position, $cells) && $cells[$position] == 1) {
  20.         $cells[$position] = 0;
  21.         if ($direction == 'left') {
  22.             $shift = -$shift;
  23.         }
  24.         for ($i = $position + $shift; array_key_exists($i, $cells); $i += $shift) {
  25.             if ($cells[$i] == 0) {
  26.                 $cells[$i] = 1;
  27.                 break;
  28.             }
  29.         }
  30.     }
  31.     $command = readline();
  32. }
  33. echo implode(' ', $cells);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement