結果

問題 No.345 最小チワワ問題
ユーザー sorchsorch
提出日時 2020-12-31 10:41:14
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,092 bytes
コンパイル時間 3,201 ms
コンパイル使用メモリ 32,144 KB
実行使用メモリ 32,660 KB
最終ジャッジ日時 2024-04-17 15:30:27
合計ジャッジ時間 5,932 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
32,400 KB
testcase_01 AC 31 ms
32,528 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 34 ms
32,400 KB
testcase_06 AC 33 ms
32,340 KB
testcase_07 AC 31 ms
32,400 KB
testcase_08 AC 31 ms
32,404 KB
testcase_09 AC 34 ms
32,404 KB
testcase_10 AC 31 ms
32,344 KB
testcase_11 AC 32 ms
32,400 KB
testcase_12 WA -
testcase_13 AC 31 ms
32,276 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 31 ms
32,344 KB
testcase_20 AC 34 ms
32,340 KB
testcase_21 WA -
testcase_22 AC 32 ms
32,344 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 30 ms
32,276 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

/**
 * @see https://yukicoder.me/problems/no/345
 */

$S = str_split(trim(fgets(STDIN)));
$chiwawaColumns = [];

for ($i = 0; $i < count($S); $i++) {
    $char = $S[$i];
    switch ($char) {
        case 'c':
            $chiwawaColumns[]['c'] = $i;
            break;
        case 'w':
            array_walk($chiwawaColumns, function (&$item, $j, $i) {
                if (array_key_exists('w2', $item)) {
                    return; // チワワ列が完成している場合は何もしない(最小チワワとするため)
                }
                if (array_key_exists('w1', $item)) {
                    $item['w2'] = $i;
                } else {
                    $item['w1'] = $i;
                }
            }, $i);
            break;
    }
}

if (empty($chiwawaColumns)) {
    $ret = -1;
} else {
    $chiwawaColumnLengthList = array_map(function ($column) {
        if (array_key_exists('w2', $column)) {
            return $column['w2'] - $column['c'] + 1;
        }
    }, $chiwawaColumns);
    $ret = min($chiwawaColumnLengthList);
}

echo $ret . "\n";
0