結果

問題 No.345 最小チワワ問題
ユーザー sorchsorch
提出日時 2020-12-31 10:55:49
言語 PHP
(8.3.4)
結果
WA  
実行時間 -
コード長 1,141 bytes
コンパイル時間 1,271 ms
コンパイル使用メモリ 31,036 KB
実行使用メモリ 31,112 KB
最終ジャッジ日時 2024-04-17 16:00:48
合計ジャッジ時間 3,991 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
30,760 KB
testcase_01 AC 41 ms
30,780 KB
testcase_02 AC 42 ms
30,860 KB
testcase_03 AC 41 ms
30,852 KB
testcase_04 AC 41 ms
31,036 KB
testcase_05 AC 43 ms
30,972 KB
testcase_06 AC 42 ms
31,004 KB
testcase_07 AC 43 ms
30,992 KB
testcase_08 AC 42 ms
30,980 KB
testcase_09 AC 42 ms
31,048 KB
testcase_10 AC 44 ms
30,736 KB
testcase_11 AC 43 ms
31,112 KB
testcase_12 WA -
testcase_13 AC 42 ms
30,868 KB
testcase_14 AC 43 ms
30,828 KB
testcase_15 AC 42 ms
30,756 KB
testcase_16 AC 43 ms
30,976 KB
testcase_17 AC 42 ms
30,824 KB
testcase_18 AC 41 ms
30,864 KB
testcase_19 AC 41 ms
31,052 KB
testcase_20 AC 41 ms
30,936 KB
testcase_21 WA -
testcase_22 AC 42 ms
30,712 KB
testcase_23 AC 41 ms
30,888 KB
testcase_24 AC 41 ms
30,780 KB
testcase_25 AC 42 ms
30,900 KB
testcase_26 AC 41 ms
30,920 KB
testcase_27 AC 44 ms
30,756 KB
testcase_28 WA -
testcase_29 AC 41 ms
31,020 KB
testcase_30 AC 41 ms
30,948 KB
testcase_31 AC 41 ms
30,964 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;
        } else {
            return PHP_INT_MAX;
        }
    }, $chiwawaColumns);
    $ret = min($chiwawaColumnLengthList);
}

echo $ret . "\n";
0