Submission #6711809


Source Code Expand

Copy
<?php
$s = str_split(trim(fgets(STDIN)));
$n = count($s);
$res = [];
for ($i = 0; $i < $n; $i++) {
    $res[$i] = 0;
}
for ($i = 0; $i < $n; $i++) {
    if ($i < $n - 1 && $s[$i] === 'R' && $s[$i + 1] === 'L') {
        $x = $i;
    }
    if ($s[$i] === 'L') {
        if (($i - $x) % 2 === 0) {
            $res[$x]++;
        } else {
            $res[$x + 1]++;
        }
    }
}
for ($i =  $n - 1; $i >= 0; $i--) {
    if ($i > 0 && $s[$i] === 'L' && $s[$i - 1] === 'R') {
        $x = $i;
    }
    if ($s[$i] === 'R') {
        if (($x - $i) % 2 === 0) {
            $res[$x]++;
        } else {
            $res[$x - 1]++;
        }
    }
}
echo implode(' ', $res).PHP_EOL;

Submission Info

Submission Time
Task D - Gathering Children
User hideyuk1
Language PHP7 (7.0.15)
Score 400
Code Size 711 Byte
Status
Exec Time 44 ms
Memory 15992 KB

Test Cases

Set Name Score / Max Score Test Cases
All 400 / 400 sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14, testcase_15, testcase_16, testcase_17, testcase_18
Sample 0 / 0 sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 9 ms 4604 KB
sample_02 9 ms 4604 KB
sample_03 9 ms 4604 KB
testcase_01 29 ms 10872 KB
testcase_02 28 ms 10872 KB
testcase_03 44 ms 15992 KB
testcase_04 42 ms 15992 KB
testcase_05 30 ms 10872 KB
testcase_06 34 ms 15352 KB
testcase_07 40 ms 15992 KB
testcase_08 40 ms 15992 KB
testcase_09 16 ms 6648 KB
testcase_10 40 ms 15992 KB
testcase_11 41 ms 15992 KB
testcase_12 41 ms 15864 KB
testcase_13 40 ms 15992 KB
testcase_14 40 ms 15992 KB
testcase_15 40 ms 15992 KB
testcase_16 40 ms 15992 KB
testcase_17 40 ms 15992 KB
testcase_18 9 ms 4604 KB