結果

問題 No.345 最小チワワ問題
ユーザー peta727peta727
提出日時 2016-05-12 14:14:10
言語 PHP
(8.3.4)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,919 bytes
コンパイル時間 138 ms
コンパイル使用メモリ 31,272 KB
実行使用メモリ 31,680 KB
最終ジャッジ日時 2024-04-16 17:41:24
合計ジャッジ時間 2,672 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 47 ms
31,048 KB
testcase_01 AC 46 ms
31,368 KB
testcase_02 AC 43 ms
31,476 KB
testcase_03 AC 42 ms
31,044 KB
testcase_04 AC 42 ms
31,480 KB
testcase_05 AC 42 ms
31,368 KB
testcase_06 AC 41 ms
31,492 KB
testcase_07 AC 41 ms
31,044 KB
testcase_08 AC 42 ms
31,412 KB
testcase_09 AC 42 ms
31,188 KB
testcase_10 AC 42 ms
31,480 KB
testcase_11 AC 42 ms
31,356 KB
testcase_12 AC 42 ms
31,140 KB
testcase_13 AC 41 ms
31,380 KB
testcase_14 AC 41 ms
31,252 KB
testcase_15 AC 42 ms
31,324 KB
testcase_16 AC 43 ms
31,392 KB
testcase_17 AC 42 ms
31,544 KB
testcase_18 WA -
testcase_19 AC 42 ms
31,204 KB
testcase_20 AC 42 ms
31,288 KB
testcase_21 AC 42 ms
31,280 KB
testcase_22 AC 41 ms
31,124 KB
testcase_23 AC 41 ms
31,108 KB
testcase_24 WA -
testcase_25 AC 42 ms
31,432 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 41 ms
31,272 KB
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 42 ms
31,024 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
No syntax errors detected in Main.php

ソースコード

diff #

<?php

/*
* Input/Output用のクラス
*/

namespace Coder;

class IO
{
    private $raw = [];
    private $count = 0;
    private $pointer = 0;

    /*
     * デリミタで区切った文字列を取得する
     * @param string
     * @return string
     */
    public function next($del = ' ') {
        if ($this->pointer >= $this->count) {
            $this->raw = explode("{$del}", trim(fgets(STDIN)));
            $this->count = count($this->raw);
            $this->pointer = 0;
        }
        $result = $this->raw[$this->pointer];
        $this->pointer++;
        return $result;
    }
    /*
     * 次にまだ文字列があるかを調べる
     * @return bool
     */
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    /*
     * int型で文字列を取り出す
     * @return int
     */
    public function nextInt($del = ' ') {
        return (int)$this->next($del);
    }
    /*
     * double型で文字列を取り出す
     * @return double
     */
    public function nextDouble($del = ' ') {
        return (double)$this->next($del);
    }
    /*
     * 改行を末尾に追加して出力する
     * @param string
     */
    public static function out ($str = '') {
        echo $str . PHP_EOL;
    }
}

$io = new IO();

$str = $io->next();
$count_c = 0;
$count_w = 0;
$index = [];
$min = strlen($str);

for($i = 0; $i < strlen($str); $i++) {
    if ($str[$i] == 'c') {
        if ($count_c == 0) {
            $count_w = 0;
        }
        $count_c = 1;
        $index[] = $i;
    }
    if ($str[$i] == 'w') {
        $count_w++;
        if ($count_c == 1 && $count_w == 2) {
            foreach ($index as $v) {
                $tmp = $i - $v + 1;
                if ($min > $tmp && $tmp > 2) {
                    $min = $tmp;
                }
            }
            $io->out($min);
            exit;
        }
    }
}
$io->out('-1');
0