Submission #46598129


Source Code Expand

<?php

[$N, $M, $H, $K] = sscanf(trim(fgets(STDIN)), "%d %d %d %d\n");
$S = str_split(trim(fgets(STDIN)));
$Q = [];
for ($i = 0; $i < $M; $i++) {
    $k = trim(fgets(STDIN));
    $Q[$k] = 1;
}

$c = [0, 0];
$ans = true;
foreach ($S as $i => $v) {
    if ($v == "R") {
        $c = [$c[0] + 1, $c[1]];
    } elseif ($v == "L") {
        $c = [$c[0] - 1, $c[1]];
    } elseif ($v == "U") {
        $c = [$c[0], $c[1] + 1];
    } else {
        $c = [$c[0], $c[1] - 1];
    }
    $H -= 1;
    $k = "$c[0] $c[1]";
    if ($H < 0) {
        $ans = false;
        break;
    } else {
        if (array_key_exists($k, $Q) && $H < $K && $Q[$k]) {
            $Q[$k] = 0;
            $H = $K;
        }
    }
    # echo "Now: ($k) / Health: $H\n";
}

echo (($ans) ? "Yes" : "No"), "\n";

Submission Info

Submission Time
Task C - Dash
User iigau
Language PHP (php 8.2.8)
Score 300
Code Size 815 Byte
Status AC
Exec Time 94 ms
Memory 45504 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 20
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_test_01.txt, 01_test_02.txt, 01_test_03.txt, 01_test_04.txt, 01_test_05.txt, 01_test_06.txt, 01_test_07.txt, 01_test_08.txt, 01_test_09.txt, 01_test_10.txt, 01_test_11.txt, 01_test_12.txt, 01_test_13.txt, 01_test_14.txt, 01_test_15.txt, 01_test_16.txt, 01_test_17.txt, 01_test_18.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 12 ms 21020 KiB
00_sample_02.txt AC 12 ms 20940 KiB
01_test_01.txt AC 94 ms 45504 KiB
01_test_02.txt AC 76 ms 38224 KiB
01_test_03.txt AC 75 ms 38424 KiB
01_test_04.txt AC 44 ms 30056 KiB
01_test_05.txt AC 44 ms 30460 KiB
01_test_06.txt AC 43 ms 30504 KiB
01_test_07.txt AC 39 ms 30696 KiB
01_test_08.txt AC 48 ms 30708 KiB
01_test_09.txt AC 47 ms 30828 KiB
01_test_10.txt AC 20 ms 30680 KiB
01_test_11.txt AC 26 ms 30412 KiB
01_test_12.txt AC 31 ms 30696 KiB
01_test_13.txt AC 46 ms 30616 KiB
01_test_14.txt AC 42 ms 30588 KiB
01_test_15.txt AC 48 ms 30688 KiB
01_test_16.txt AC 42 ms 30668 KiB
01_test_17.txt AC 46 ms 30660 KiB
01_test_18.txt AC 41 ms 30732 KiB