Submission #6738627


Source Code Expand

Copy
<?php
// 入力
$s = trim(fgets(STDIN));

$n = strlen($s);

// 答え出力用配列に0格納
$ans = array_fill(0, $n, 0);

// 計算
$top = 0;
while($top < $n) {
    if ($s[$top] === 'R') $next = 'L';
    else $next = 'R';

    $next_top = strpos($s, $next, $top);
    if (!$next_top) $next_top = $n;

    $cnt = $next_top - $top;

    if ($s[$top] === 'R') {
        $x0 = $top + $cnt - 1;
        $x1 = $x0 + 1;
    } else {
        $x0 = $top;
        $x1 = $x0 - 1;
    }
    $ans[$x0] += ceil($cnt / 2);
    $ans[$x1] += floor($cnt / 2);

    $top = $next_top;
}

// 出力
echo implode(' ', $ans).PHP_EOL;

Submission Info

Submission Time
Task D - Gathering Children
User hideyuk1
Language PHP7 (7.0.15)
Score 400
Code Size 647 Byte
Status
Exec Time 66 ms
Memory 35576 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 10 ms 4604 KB
sample_02 10 ms 4604 KB
sample_03 10 ms 4604 KB
testcase_01 29 ms 14968 KB
testcase_02 29 ms 14968 KB
testcase_03 42 ms 23288 KB
testcase_04 41 ms 23288 KB
testcase_05 11 ms 6776 KB
testcase_06 12 ms 10872 KB
testcase_07 13 ms 11000 KB
testcase_08 13 ms 11000 KB
testcase_09 11 ms 4728 KB
testcase_10 13 ms 11000 KB
testcase_11 66 ms 35576 KB
testcase_12 13 ms 11000 KB
testcase_13 13 ms 11000 KB
testcase_14 13 ms 11000 KB
testcase_15 13 ms 11000 KB
testcase_16 13 ms 11000 KB
testcase_17 13 ms 11000 KB
testcase_18 10 ms 4604 KB